Solved

Simple Dynamaic Event Question

Posted on 2003-11-12
3
170 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now