Pass TClientDataSet as param

(using Delphi Berlin Enterprise)

I have a method defined as:


function TdmPSI.PrepCdsFromFldLst(cds: TClientDataSet; forExport:boolean): boolean;



I was hoping to use something like this do use it in scripter:


  Scripter.DefineMethod('PrepCdsFromFldLst', 2, TAtTypeKind.tkEnumeration, nil,
      PrepCdsFromFldLstProc, False, 0);

procedure TEDIValidate850Library.PrepCdsFromFldLstProc(
  aMachine: TatVirtualMachine);
begin
 with aMachine do begin
     ReturnOutputArg(
       dmPSI.PrepCdsFromFldLst( TClientDataSet( GetInputArgAsVariant(0) ),
                                               GetInputArgAsBoolean(1)
                              )

     );
  end;
end;



Of course, it's never that simple: I get "Invalid Typecast" at TClientDataset(...) .

How do I get that first param returned as a TClientDataSet?

Cheers,
EdB

You can use 



TClientDataset(GetInputArgAsObject(0))

or


TClientDataset(VarToObject(GetInputArg(0)))

Wagner R. Landgraf2017-07-09 20:51:16

That worked... I was so close: "...AsVariant" instead of "..AsObject".

Well, one more item in the "hints and tips" collection.

For
anyone else looking at this, the first thing you should do is remove
the 2nd "As" in the "GetInputArgAsAsObject" - I didn't notice that at
first and almost shrugged it off as "some old way" when it failed tp
compile -leaving me with the single option of using the VarToObject
call.

In my defense, I AM on holiday and it's pretty early in the morning for me... :)

Thanks Wagner!

Cheers,
EdB

Oops, sorry for the typo. I have edited my answer to fix it... :-)