?
Solved

Simple Dynamaic Event Question

Posted on 2003-11-12
3
Medium Priority
?
178 Views
Last Modified: 2010-04-05
Ok, i'm sure this is very simple, but as it is i can't find it anywhere online, and i'm basically driving myself insane.  currently i am creatign dynamic components and adding them to the surrent form, and all i want to do in the world is add an onClick handler to these compoents, the important code is below.

field := TTabSheet.create(self);
//create quizes tab
with field do
begin
  caption := 'Students';
  PageControl := subjectPages[index];
  Height := 425;
  Width := 785;
  with TStringGrid.Create(self) do
  begin
    parent := field;
    height := 425;
    width := 785;
  end;
end;

now i figured i could just do a onClick := "a procedure here"; and be done with it, but that hasn't worked very well, which is to say not at all. If anybody could just show me how this is done dynamically, in the code, without using the object inspector i would be quite pleased.
Thanks,
MindKiller
0
Comment
Question by:MindKiller
[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
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 150 total points
ID: 9737124
What I usually do is drop a like component on the form, name it the same as the one I'm going to dynamically
create and then dbl=click it's OnClick procedure in the OI to create the procedure, add a comment in the procedure
so it won't get deleted, and then delte the component I dropped on the form. Then all you have to do is

  MyDynamicallyCreatedcomponent.onClick := MyDroppedCompnentClick;
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9737275
I don't exactly understand what you mean, but does this help? (I have commented the withs so that we know exactly what is being assigned).


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    subjectPages: TPageControl;
    procedure Button1Click(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var
  field : TTabSheet;
  MyGrid: TStringGrid;
begin

field := TTabSheet.create(self);
//create quizes tab
//with field do
begin
  field.caption := 'Students';

  field.PageControl := subjectPages;//[subjectPages.TabIndex];
  field.Height := 425;
  field.Width := 785;
  field.onClick := FormClick;//call formclick on click of TTabSheet
   MyGrid := TStringGrid.Create(self);
//  with MyGrid do
  begin
    MyGrid.parent := field;
    MyGrid.height := 425;
    MyGrid.width := 785;
    MyGrid.onClick := FormClick;//call formclick on click on TStringGrid
  end;
end;

end;

procedure TForm1.FormClick(Sender: TObject);//onclick procedure
begin
  showmessage('Hi');
end;

end.

0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9737285
Note:
Your onclick procedure has to be declared as (i.e. its prototype shoud be):
procedure MyClickProcedure(Sender: TObject);

Tou CANNOT have something like
procedure MyClickProcedure(someotherparameter:string; yetanotherparameter:integer);

for onclick
Perhaps that would help clarify.
:-)
...Snehanshu
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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

762 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