Problem with Index specifiers in format function

Good Day,

Using Index specifiers for format results in exception.

Ex:

format(abc.link(“%0:s”),[‘temp’]) results in error

so we changed the LOC to format(abc.link(“%s”),[‘temp’])

Hi,

Can you create a simple testcase that reproduces this, pls?

as for me, index specifiers work correctly:

please find the sample code
Sample.pas (3.8 KB)

it works well in normal way, but when integrated with pascal script we were getting blank values

Hi,

ofc, it won’t work correctly - your testcase is broken (I’ve used Delphi 11.3)

you have

function MyOwnFunction(Data: ansistring): ansistring;
begin
  xxx := data;
end;

but function is registered as

Sender.AddDelphiFunction('function MyOwnFunction(Data: string):string');

if you change ansistringstring, it will work:


this was the O/P when i use string
and

this when i use ansistring

PFA
Sample.pas (3.8 KB)

Hi,

I’ve committed a new fix to GitHub - remobjects/pascalscript: pascalscript .

also I’ve fixed wrong declaration at Sample.pas (3.8 KB)

Hi,
Thanks for the fix, u sorry to say it didn’t work for me. Am using D11 32-bit and 64-bit. Don’t know whether this info. helps, but i thought you should know.

Hi,

as a workaround, I can suggest to use this method instead of System.AnsiStrings.Format:

function MyFormat(const Format: AnsiString; const Args: array of const): AnsiString;
var
  args1 : TArray<TVarRec>;
begin
  Args1 := TValueArrayToArrayOfConst(ArrayOfConstToTValueArray(Args));
  result := System.AnsiStrings.Format(Format, Args1);
end;
function ScriptOnUses(Sender: TPSPascalCompiler;...
...
Sender.AddDelphiFunction('function Format(const Format: Ansistring; const Args: array of const): Ansistring;');
procedure ExecuteScript(const script: string; sqlconn: TSQLConnection);
...
  Exec.RegisterDelphiFunction(@MyFormat, 'Format', cdRegister);

Sample.pas (4.0 KB)