|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic component events
Hi all
Anybody know how to assign a mousemove event to a dynamic component I have already created a series of checkboxes using (TmpCheck) as a TCheckBox component , and want to assign a mouse move event to each of the dynamically created check boxes. This is what I think should be the call... TmpCheck.OnMouseMove := MyMouseMove( TmpCheck, ?, TmpCheck.Left, TmpCheck.Top ); The above should then in turn call... procedure TForm1.MyMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin blah blah blah end; The only problem with calling the procedure, is TShiftState. I tried passing ssShift (as per D7 help files) just to fill the param gap, but D7 returns... [Error] Unit1.pas(95): Incompatible types: 'TShiftState' and 'Enumeration' [Error] Unit1.pas(95): Incompatible types: 'TMouseMoveEvent' and 'procedure, untyped pointer or untyped parameter' Any ideas? Cheers |
|
#2
|
||||
|
||||
|
In the private section of your form, declare a procedure like this:
Code:
private
{ Private declarations }
procedure MyMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Then, assign this event to your dynamic checkboxes like this: cb.OnMouseMove := MyMouseMove; Here's a sample program that I wrote. The program creates 10 checkboxes dynamically when you click on a button. Then, when you move your mouse over a checkbox, the MyMouseMove event handler determines which checkbox it is and adjusts its caption accordingly. Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure MyMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.MyMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Edit1.Text := 'Your mouse is now on ' + TCheckBox(Sender).Caption;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
cb : TCheckBox;
i : integer;
begin
for i := 1 to 10 do
begin
cb := TCheckBox.Create(self);
cb.Parent := self;
cb.Caption := 'Checkbox ' + IntToStr(i);
cb.Left := 100; cb.Top := i * 20;
cb.OnMouseMove := MyMouseMove;
end;
end;
end.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
|||
|
|||
|
Very helpful - thank you
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Dynamic component events |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|