Search code examples
delphifreepascalpascalscript

TStringList ValueFromIndex not working in PascalScript


I'm trying to use TStrings.ValueFromIndex (which works in FreePascal and Delphi) in a PascalScript function, but it doesn't work, the compiler returns:

                                        Unknown identifier 'GETVALUEFROMINDEX'

I'm using it well?
Is this functionality available in PascalScript?
if not, is there any easy way to do that?

THE CODE:

Function dummy(R: TStringList):String;
var
   i: Integer;
   RESULTv: string;
begin
   for i := 0 to ReqList.Count-1 do
     RESULTv := RESULTv + R.Names[i]+' -> '+ R.ValueFromIndex[i];
   dummy := RESULTv;
end;

Solution

  • PascalScript's TStrings is a Delphi TStrings, but the ValueFromIndex method is not exposed by PascalScript. This can be seen by reading SIRegisterTStrings.

    So, you need to make use of what is available. For instance the Values property:

    RESULTv := RESULTv + R.Names[i] + ' -> ' + R.Values[R.Names[i]];
    

    Or you might prefer to avoid some repetition with

    Name := R.Names[i];
    RESULTv := RESULTv + Name + ' -> ' + R.Values[Name];
    

    This is rather inefficient, but unless you are going to parse the name/value pairs yourself, it's probably the best that you can do.

    If you felt brave, you could compile PascalScript yourself, and add a call to RegisterMethod in SIRegisterTStrings that registered ValueFromIndex.