Recent

Author Topic: [ Solved ] howto set onmousemove handler after image.create  (Read 260 times)

Jumbo

  • New Member
  • *
  • Posts: 29
[ Solved ] howto set onmousemove handler after image.create
« on: October 01, 2023, 01:52:54 pm »
Cant find a solution for this:

After creating an image on runtime, howto create the onmousmove handler.

  Image1 := TImage.Create(Form1);
  Image1.Parent := Form1;
  ==>?  Image1.OnMouseMove:= ... ?<==

I expect somting to write like:

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  doing something ...
end;

But that just does not work ...
« Last Edit: October 01, 2023, 02:57:48 pm by Jumbo »

Fibonacci

  • Full Member
  • ***
  • Posts: 219
  • #PDK
Re: howto set onmousemove handler after image.create
« Reply #1 on: October 01, 2023, 02:08:52 pm »
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     Button1: TButton;
  4.     procedure Button1Click(Sender: TObject);
  5.     procedure yourhandler(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  6.   private
  7.   public
  8.   end;
  9.  
  10. var
  11.   Form1: TForm1;
  12.  
  13. implementation
  14.  
  15. {$R *.lfm}
  16.  
  17. procedure TForm1.yourhandler(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  18. begin
  19.   Form1.Caption := IntToStr(X)+' x '+IntToStr(Y)+' -- your handler';
  20. end;
  21.  
  22. procedure TForm1.Button1Click(Sender: TObject);
  23. var
  24.   Image1: TImage;
  25. begin
  26.   Image1 := TImage.Create(Form1);
  27.   Image1.Parent := Form1;
  28.  
  29.   with Image1 do begin
  30.     Left := 0;
  31.     Top := 0;
  32.     Width := Form1.Width;
  33.     Height := Form1.Height;
  34.   end;
  35.  
  36.   // this
  37.   //Image1.OnMouseMove := procedure(Sender: TObject; Shift: TShiftState; X, Y: Integer)
  38.   //begin
  39.   //  Form1.Caption := IntToStr(X)+' x '+IntToStr(Y)+' -- anon proc';
  40.   //end;
  41.  
  42.   // or this
  43.   Image1.OnMouseMove := @yourhandler;
  44. end;

For anonymouse functions you need {$modeswitch anonymousfunctions} and FPC trunk.

I had to lower the FPS for the GIF to 9 to fit in allowed attachment max size of 500 kB 8)
« Last Edit: October 01, 2023, 02:11:38 pm by Fibonacci »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: howto set onmousemove handler after image.create
« Reply #2 on: October 01, 2023, 02:57:22 pm »
Unbelievable simple....  Works as expected.

Thanks a lot.

 

TinyPortal © 2005-2018