Tpoint and GetcursorPos

Hello,

I'am trying to add GetCursorPos function to scripter but I have a problem, as always after a long time I don't handle record in scripter.

So I try this :

procedure TForm1._GetCursorPos(AMachine: TatVirtualMachine);
 var
  Param0: TPoint;
  AResult:boolean;
begin
  AResult := GetCursorPos(Param0);
  AMachine.ReturnOutputArg(AResult);
  AMachine.SetInputArg(0,NativeUInt(TPointWrapper.Create(Param0)));
end;

TPointWrapper is defined in Ap_types.pas :

  TPointWrapper = class(TatRecordWrapper)
  private
    FX: Longint;
    FY: Longint;
  public
    constructor Create(ARecord: TPoint);
    function ObjToRec: TPoint;
  published
    property X: Longint read FX write FX;
    property Y: Longint read FY write FY;
  end;

Added with :

atPascalScripter.SystemLibrary.defineMethod('GetCursorPos',1,atScript.tkInteger,nil,_GetCursorPos);

This script


var
 p:tpoint;
begin 
 GetCursorPos(P);
 ShowMessage(P.x);
end; 

return this error :
"RUNTIME ERROR Method expects argument 0 as variable reference Position: 4, 17.":

I have forgotten SetVarArgs method :

atPascalScripter.SystemLibrary.defineMethod('GetCursorPos',1,atScript.tkInteger,nil,_GetCursorPos,false,0,'lPoint:TPoint').SetVarArgs([0]);

But the script still no running correctly :

var
 p:tpoint;
 x,y:integer;
begin 
 p:=tpoint.Create; // change nothing

 GetCursorPos(p);
 ShowMessage( inttostr(p.x)+'/'+inttostr(p.y));
 end;

Return me wrong value like "1/0". Why ?

Works fine here. See project attached. Please always try to send a project reproducing the issue, thank you.

TestScripterGetCursorPos.zip (7.6 KB)

Hello Wagner,

Thank you for your sample.
I have found what cause the problem, in my ap_types.pas :

procedure TatTypesLibrary.Init;
begin
  Scripter.DefineRecordByRTTI( TypeInfo(Tpoint));
...

But why ?

Why did you add such method? It's not needed. Just removed it, use the original ap_Types unit and it will work fine as the example shows.