Solved

Simple Dynamaic Event Question

Posted on 2003-11-12
3
172 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
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 50 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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