Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 29th, 2004, 12:12 PM
ECSUK ECSUK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: North Yorkshire (U.K.)
Posts: 64 ECSUK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 24 m 18 sec
Reputation Power: 8
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

Reply With Quote
  #2  
Old April 29th, 2004, 04:52 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,691 Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 3 h 3 m 39 sec
Reputation Power: 1145
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

Reply With Quote
  #3  
Old April 29th, 2004, 08:53 PM
ECSUK ECSUK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: North Yorkshire (U.K.)
Posts: 64 ECSUK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 24 m 18 sec
Reputation Power: 8
Thumbs up

Very helpful - thank you

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Dynamic component events


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT