Link to home
Start Free TrialLog in
Avatar of MindKiller
MindKiller

asked on

Simple Dynamaic Event Question

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
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snehanshu
snehanshu

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.

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