Does anyone know which of these are quicker?

procedure SetMousePos(Point: TPoint);
begin
  Mouse.CursorPos := Point;
end;

function GetMousePos: TPoint;
begin
  Result := Mouse.CursorPos;
end;
procedure SetMousePos(Point: TPoint);
begin
  SetCursorPos(Point.X, Point.Y);
end;

function GetMousePos: TPoint;
begin
  GetCursorPos(Result);
end;

Recommended Answers

All 2 Replies

Ah~Every procedure only has one sentence,so directly use(don't use in procedure) may quicker.And I think,Mouse.CursorPos may be quicker.
And there is another way(perhaps quicker):

Procedure GetMouse(Var s,x,y:Word);
 Var
  _s,_x,_y:Word;
 Begin
  Asm
   MOV ax,3
   INT $33
   MOV _s,bx
   MOV _x,cx
   MOV _y,dx
  End;
  s:=_s;
  x:=_x;
  y:=_y;
 End;
Procedure SetMouse(x,y:Word);
 Begin
  Asm
   MOV ax,4
   MOV cx,x
   MOV dx,y
   INT $33
  End;
 End;

If you really want to know in detail, profile it. Add timing functions and run them a couple of thousand times. GetCursorPos is a windows call. Mouse.CursorPos is a VCL wrapper that calls a method that calls GetCursorPos . So in theory the former is always faster.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.