remobjects / pascalscript

pascalscript
Other
450 stars 182 forks source link

How to pass object as parameter #216

Open bamsey2k1 opened 4 years ago

bamsey2k1 commented 4 years ago

How to pass Object or Record to PascalScript as function parameter

function Test(Sender: TObject); begin //manipulate Sender end;

Now i'm getting Invalid parameter exception

maxkleiner commented 4 years ago

you mean a cast or methodpointer?: function Test(Sender: TObject): boolean; begin //manipulate Sender or cast it TForm(sender).tag; end;

bamsey2k1 commented 4 years ago

i mean pass TObject from DelphiCode To PascalScript

vParams is array of Variant so it can't held an Object ProcNo := TPSExec(fExec).GetProc(TbtString('test')); if ProcNo > -1 then TPSExec(fExec).RunProcP(vParams, ProcNo);

is there another way to call function with TObject parameter and return this function Result?

maxkleiner commented 4 years ago

My first reaction asking you why you are storing TObjects in a list of variants, but assuming you have a good reason (maybe to call class methods in PS)! You can't store plain objects as a variant. But you can store interfaces. You can also cast TObject to Pointer to Integer and store that as Int. But i'm not sure if that's what you really want.

``` for i:=0 to High(varArray) do MyProcedure (TObject(varArray[i]));