Author Topic: Archive Extension grid column  (Read 7169 times)

0 Members and 1 Guest are viewing this topic.

Padanges

  • Newbie
  • *
  • Posts: 179
Archive Extension grid column
« on: August 24, 2016, 12:40:03 PM »
Hi,
I would like to create a "dynamically calculated column" by using "eval expression" which would hold Archive column entry filename extensions, that is, to create a column "Archive Extension". What syntax should I use?


Thanks in advance.

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #1 on: August 24, 2016, 01:11:12 PM »
On the other hand, a column of zeros/ones for Archive indication would be sufficient. Can I create that using the dynamic calculation? Could you give an example?

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #2 on: August 24, 2016, 01:31:27 PM »
Found the answer within documentation pages  ;D
"Dynamically calculated column expression to return the file extension. Useful to sort by file type (zip, rar, pdf, chm, ...)"
Code: [Select]
begin
var 'i','s' end;
$s:=an;
if $s='' then
$s:=f;
endif;
$i:=pos('.',reversestr($s));
if $i>0 then
return(lowercase(rightstr($s,$i-1)));
else
return('');
endd;
end
Is this syntax based on any language?

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #3 on: August 24, 2016, 02:08:21 PM »
OK, let's change a question a bit. Here we have a code to find the first match of a Grid filename which has a character "!" (#33) using function pos().
Code: [Select]
begin
var 'i','n' end;
$n:=grid.numrows;
for $i:=0;$i<$n; $i++ do
if pos(#33, grid.cell(fn,$i))<>0 then
// check file names for "!"
return($i+1+#32+grid.cell(f,$i)+#32);
// ASCII code for space is #32
endif;
next;
return('-');
end
But the code gives no answer. Could you help with this? Documentation description for the pos() function is quite minimal. I guess that's where the problem lies.

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #4 on: August 24, 2016, 02:17:50 PM »
If one would like to match, for example, file names which have words "and" in it, would it be possible to do that using: pos(#97#110#100, grid.cell(lowercase(fn),$i))<>0; as in the previous script?

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Archive Extension grid column
« Reply #5 on: August 25, 2016, 12:39:04 AM »
But the code gives no answer. Could you help with this? Documentation description for the pos() function is quite minimal. I guess that's where the problem lies.
Just change fn to f in the pos function call. Fn doesn't exist as field reference constant.
The pos function reference .

If one would like to match, for example, file names which have words "and" in it, would it be possible to do that using: pos(#97#110#100, grid.cell(lowercase(fn),$i))<>0; as in the previous script?
Sure, but there is not need to use char codes for that. Just type the string you want to find, using single quotes. i.e pos('and', lowercase(grid.cell(f,$i)))>0.
The lowercase function is to be used in the grid.cell result, not to pass the field name lowercased. And again, the filename reference constant is f, not fn.

Is this syntax based on any language?
This weird syntax is from a component named TArtFormula. Google it if you want to know more. The credits to the author are in the program about box.

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #6 on: August 25, 2016, 11:13:37 AM »
Thanks, the code works fine now :)
We can dynamically check for substring in a given string, for example, for a sequence of characters in a given file name string. But can we check whether it contains any digits (without using a cycle which loops through all the possible number characters)? More specifically, can we dynamically check for any four digit integers present?
Are we bound to use only the functions (for dynamic evaluations) given in this list: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System.html ?

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Archive Extension grid column
« Reply #7 on: August 26, 2016, 01:34:23 AM »
But can we check whether it contains any digits (without using a cycle which loops through all the possible number characters)? More specifically, can we dynamically check for any four digit integers present?
No specific function for that, so no.
Quote
Are we bound to use only the functions (for dynamic evaluations) given in this list: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System.html ?
You can get the list of the currently supported functions from the user's guide.

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Archive Extension grid column
« Reply #8 on: August 27, 2016, 06:55:36 AM »
Can we have subprocedures (user defined functions) within "eval expression"?

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Archive Extension grid column
« Reply #9 on: August 28, 2016, 05:29:45 PM »
Can we have subprocedures (user defined functions) within "eval expression"?
No. But the component can be extended with custom functions, so I'm going to check the feasibility of a custom function to call a script  ;)