Home RAP

Passing TStringList object from RAP...

edited September 2003 in RAP
Hi,
When I try to pass an object of TStringList type from RAP to my pass-through
"ExecuteReport" function I get a nil reference instead of an object itself.
Could you please
look at the following code and tell me what is wrong?

In the RAP I do the following:

procedure GlobalOnCreate
Var
Params :TStringList;
begin
Params:=TStringList.Create;
Params.Add('StockHeaderId'+'='+'2628');
ExecuteReport(17, Params, dtPrinter, true);
Params.Free;
end;

My function ExecuteReport does this:

class function TRAP_ExecuteReport.GetSignature: String;
begin
Result := 'function ExecuteReport(RepId :Variant; Params:TStringList;
PrintDevice:String; ShowPrinterDialog:Boolean):Boolean;';
end;

procedure TRAP_ExecuteReport.ExecuteFunction(aParams: TraParamList);
Var
RepId :Variant;
MyParams :TStringList;
Params :THashedStringList;
PrintDevice :String;
ShowPrinterDialog :Boolean;
Res :Boolean;
i :Integer;
begin
Params:=THashedStringList.Create;
GetParamValue(0, RepId);
GetParamValue(1, MyParams); //here GetParamValue returns nil for
MyParams variable
GetParamValue(2, PrintDevice);
GetParamValue(3, ShowPrinterDialog);
for i:=0 to MyParams.Count-1 do begin //here the method throws an
exception since MyParams=nil
Params.Add(MyParams[i]);
end;

Res:=DataModuleUnit.SilentReportCall(RepId,Params,PrintDevice,ShowPrinterDia
log);
SetParamValue(4, Res);
Params.Free;
end;

When I look at the "Params" variable value in Delphi at run time it tells me
that it is nil.

How can I properly get an object from RAP for manipulation in my functions?

Thanks,
MB.

Comments

  • edited September 2003
    Also, as a workaround I could use TStringList.CommaText property, but
    how do
    I make it visible for RAP? When I try this string:
    "showmessage(Params.CommaText);"
    the following error is being rased: "Expected '(' or '[' but found
    'CommaText' instead.

  • edited September 2003
    Hi Moisey,


    Is the string list created when you call it in RAP code?

    Try setting this to be a var parameter on the pass thru function to see if
    that helps. Perhaps it need to be pass by value instead of by reference for
    GetParams to work properly.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited October 2003
    Remarkably, I had exactly the same issue arise today( wanting to pass a
    TStringList reference from a RAP function and read its strings after it
    is populated). The StringList variable holding the result of the Create
    in the RAP function seems to be nil (Note the line below where the AV
    occurs). Is it possible to pass a TStringList object as a parameter from
    a RAP procedure and read its values after it has been populated by
    another function which takes it as a var parameter?

    I have a [test] procedure that populates a StringList:

    procedure UnitA.MyProcedure(aThing, aNotherThing:integer; var
    aList;TStringList);
    begin
    aList:=TStringList.Create;
    if aThing = 1 then aNotherThing := 99 else aNotherThing := 100;
    aList.Add(inttostr(aNotherThing);
    aList.Add('Some text');
    aList.Add('Some more text');
    end;

    Then, in another unit (for the RAP function):

    class function myRAPunit.GetSignature: string;
    begin
    Result:=' MyProcedure(aThing, aNotherThing:integer; var
    aList;TStringList';
    end;


    procedure myRAPunit.ExecuteFunction(aParams:TraParamList);
    var ainteger, aNotherInteger:integer;
    aLocalList:TStringList;
    begin
    aLocalList := TStringList.Create;
    GetParamValue(0, ainteger);
    GetParamValue(1, aNotherInteger);
    GetParamValue(2, aLocalList);
    showmessage('Testing for List:' + inttostr(aLocalList.Count)); <<--
    Access Violation
    MyProcedure(ainteger,aNotherInteger,aLocalList);
    SetParamValue(2, aLocalList);
    end;

    Dennis McFall
This discussion has been closed.