jasongth
asked on
Obtaining information about embedded frame component and passing it to the parentform
Hi all,
I have created a parentform and dynamically embedded with a array of frames, each containing a panel with a TSpeedButton.
My parentform has a database for information exchange and retrieval.
How do I get the attribute of which TSpeedButton I have clicked on when testing and passing it to the parentform so that the correct database access according to the button clicked is retrieved?
Even though the frames are embedded in the parentform, they do not seem to be able to communicate bi-directionally.
I have tried :
procedure TTestForm.FormMouseDown(Se nder: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Sender is TTestForm then
ShowMessage('TestForm')
else if Sender is TSpeedButton then
ShowMessage('SpeedButton') ;
//// if (Sender as TSpeedButton).HasParent = true then
//// ShowMessage('HasParent');
end;
Clicking on the parentform will pop up 'TestForm'; clicking on the embedded Frame TSpeedButton does not. Is there a way to get the handler of the clicked TSpeedButton and used it in the parentform?
I have created a parentform and dynamically embedded with a array of frames, each containing a panel with a TSpeedButton.
My parentform has a database for information exchange and retrieval.
How do I get the attribute of which TSpeedButton I have clicked on when testing and passing it to the parentform so that the correct database access according to the button clicked is retrieved?
Even though the frames are embedded in the parentform, they do not seem to be able to communicate bi-directionally.
I have tried :
procedure TTestForm.FormMouseDown(Se
Shift: TShiftState; X, Y: Integer);
begin
if Sender is TTestForm then
ShowMessage('TestForm')
else if Sender is TSpeedButton then
ShowMessage('SpeedButton')
//// if (Sender as TSpeedButton).HasParent = true then
//// ShowMessage('HasParent');
end;
Clicking on the parentform will pop up 'TestForm'; clicking on the embedded Frame TSpeedButton does not. Is there a way to get the handler of the clicked TSpeedButton and used it in the parentform?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jasongth:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
unit Trf2;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,Buttons, ExtCtrls, Dialogs;
type
TOKBottomDlg = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
Panel1: TPanel;
SpeedButton1: TSpeedButton;
procedure SpeedButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
public
{ Public declarations }
end;
var
OKBottomDlg: TOKBottomDlg;
implementation
{$R *.DFM}
procedure TOKBottomDlg.FormCreate(Se
begin
// create instances
SpeedButton3 := TSpeedButton.Create(Self);
SpeedButton2 := TSpeedButton.Create(Self);
end;
procedure TOKBottomDlg.FormShow(Send
begin
// populate attributes
with SpeedButton2 do begin
Parent := Self;
Caption := '2';
Height := 25;
Width := 25;
Left := 60;
Name := 'SpeedButton2';
Tag := 2;
Top := 80;
OnClick := SpeedButtonClick;
end;
with SpeedButton3 do begin
Parent := Self;
Caption := '3';
Height := 25;
Width := 25;
Left := 100;
Name := 'SpeedButton3';
Tag := 3;
Top := 80;
OnClick := SpeedButtonClick;
end;
end;
procedure TOKBottomDlg.SpeedButtonCl
begin
// shows which SpeedButton is pressed
MessageDlg('Speedy button:'+IntToStr(TControl
end;
end.
Comments:
I have dropped a TSpeedButton just for testing purposes
SpeedButton1 in my case
Buttons are created with the main form as owner. This avoids the need to free them.
The same event is shared by all buttons.
Attributes are assigned in main form OnShow event
Notice Parent assignment: this is currently the main form (Self) but it could and must be any other showable frame. Without this Parent assignment, SpeedButtons will never be shown.
Everything is in place.
Compile and Run the program with this form
When clicking on one of the three SpeedButtons, the message dialog box will show the corresponding tag value.
With further development, buttons could be created within an ObjectList; any other TNotifyEvent of the same type could be assigned.
Don't forget that SpeedButton are not windows but only gadgets: they do not have a window handle.
Hope this helps.
Antonio.