[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Simple Dynamaic Event Question

Posted on 2003-11-12
3
Medium Priority
?
179 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

Independent Software Vendors: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 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