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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(someother parameter: string; yetanotherparameter:intege r);
for onclick
Perhaps that would help clarify.
:-)
...Snehanshu
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(someother
for onclick
Perhaps that would help clarify.
:-)
...Snehanshu
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
Var
field : TTabSheet;
MyGrid: TStringGrid;
begin
field := TTabSheet.create(self);
//create quizes tab
//with field do
begin
field.caption := 'Students';
field.PageControl := subjectPages;//[subjectPag
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.