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)


i have used the above sample.pas file… and this was the result

I’m not sure why, but when Delphi11 and Pascalscript were used together, the format function was not functioning as it should have.

Hi,

I’m using Embarcadero® Delphi 11 Version 28.0.48361.3236 and it works for me as expected.

pls retest whole project: testcase31451.zip (9.6 KB)

Hi,

Am using Delphi 11 Version 28.0.44500.8973 … Ran the project and the output was

I even downloaded the latest pascal script from “GitHub - remobjects/pascalscript: pascalscript

Hi,

as I already said, it works as expected with Delphi 11 .8973:

I apologize for saying this over and over again. I’m receiving same results for 32- and 64-bit. It was an odd string for 64-bit and empty for 32-bit. Even though I didn’t change a single LOC in the project you provided, I’m still having problems. Are there any project options settings that I’m missing? Will the execution be affected because of project options? Would you kindly share the project options with me so that I may contrast them with mine?

Hi,

I’ve attached my project:

are you using the latest PS snapshot ? it should be

Thank you for the update. I downloaded the latest code on the 9th of this month. While it didn’t work at first, it’s working now—thank you for resolving that.

However, I’m unsure if it supports all specifiers like %f and %m. After testing the project with various options, I found that it only works for %s in both 32-bit and 64-bit environments.

Hi,

weird, %f works for me too:

I’m glad to see the anticipated results from your end.

I’ve worked on a variety of formats and combinations. Would you kindly review the shared document, if you can?
Format Examples.docx (591.9 KB)

Hi,

Can you retest with


or use
InvokeCall.inc (14.1 KB) , pls?


note: this is the same change.