Recent

Author Topic: [SOLVED] Speciying OnMouse events when creating an array of TEdits  (Read 827 times)

Hopestation

  • Full Member
  • ***
  • Posts: 181
Hi
I am using Lazarus #: 2.0.6+dfsg-3 with FPC Version: 3.0.4 In Linux.

I want to specify the OnMouseDown event as I create an array of TEdit components.

I have the procedure:

procedure TFrmLbl.EdtMouseDown(Sender: TObject; Button: TMouseButton;
                 Shift: TShiftState; X, Y: Integer);
begin
   EdtMv := True;
   Source := TEdit(Sender);
   TagNo := Source.tag;
end;

I have tried using:

   Edt[NumBx].OnMouseDown := EdtMouseDown(Sender, Button, Shift, X, Y);

and get the error messages that : Button, Shift X and Y don't exist.

How do I assign this procedure to the OnMouseDown event at design time?

Thanks
« Last Edit: April 25, 2021, 04:45:22 pm by Hopestation »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Speciying OnMouse events when creating an array of TEdits
« Reply #1 on: April 25, 2021, 04:38:16 pm »
To assign an event handler at run-time, do it like this:
Code: Pascal  [Select][+][-]
  1.    Edt[NumBx].OnMouseDown := @EdtMouseDown;

Since (I assume) you're creating the controls at run time you can't specify the handler at design-time (obviously).

It would be otherwise if you were adding them at design-time; in that case all you would need would be to assign it in the object inspector, which you can do for several controls at a time by selecting them in the components tree (with Shift+ or Ctrl+Click) and specifying the handler in the "Events" tab.

HTH!
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: Speciying OnMouse events when creating an array of TEdits
« Reply #2 on: April 25, 2021, 04:44:57 pm »
Thanks Lucamar, that's just what I was looking for.

 

TinyPortal © 2005-2018