?
Solved

Obtaining information about embedded frame component and passing it to the parentform

Posted on 2003-03-31
3
Medium Priority
?
178 Views
Last Modified: 2010-04-06
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(Sender: 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?
0
Comment
Question by:jasongth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:antonio_fortuny
ID: 8243716
Try this (it works with Delphi 5)

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(Sender: TObject);
begin
// create instances
SpeedButton3 := TSpeedButton.Create(Self);
SpeedButton2 := TSpeedButton.Create(Self);
end;

procedure TOKBottomDlg.FormShow(Sender: TObject);
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.SpeedButtonClick(Sender: TObject);
begin
// shows which SpeedButton is pressed
MessageDlg('Speedy button:'+IntToStr(TControl(Sender).Tag),mtConfirmation,[mbYes,mbNo,mbCancel],0);
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.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 375 total points
ID: 8243754
not sure for what you are after,

but a try

//MainForm
unit frame_test_main_u;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses frame_u;

{$R *.dfm}



procedure TForm1.FormClick(Sender: TObject);
begin
  if (sender is TComponent) then
    ShowMessage(TComponent(Sender).Name+' has Clicked!')
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TFrame2.Create(self,FormClick) do
  begin
    parent := self;
    show;
  end;
end;

end.


//a Frame Unit
unit frame_u;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons;

type
  TFrame2 = class(TFrame)
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
  private
    { Private declarations }
  public
    constructor Create(AOwner : TComponent; AClickEventHandler : TNotifyEvent); OverLoad;
    { Public declarations }
  end;

implementation

{$R *.dfm}

constructor TFrame2.Create(AOwner : TComponent; AClickEventHandler : TNotifyEvent);
begin
  inherited Create(AOwner);
  if assigned(AClickEventHandler) then
  begin
    SpeedButton1.OnClick := AClickEventHandler;
    SpeedButton2.OnClick := AClickEventHandler;
    SpeedButton3.OnClick := AClickEventHandler;
    SpeedButton4.OnClick := AClickEventHandler;
    SpeedButton5.OnClick := AClickEventHandler;
    SpeedButton6.OnClick := AClickEventHandler;
  end;
end;


end.


meikl ;-)
0
 

Expert Comment

by:CleanupPing
ID: 9316519
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.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question