Board index » delphi » How do I write a handler to a runtime object

How do I write a handler to a runtime object

Hi !

I create a Button:
..
..
public
    ErrClose: TButton;   {define it}
..
..

procedure TForm1.ItAndThat;
begin
 ErrClose:= TButton.Create(Self);    {create the button}
end;

I tried to write a procedure:
ErrCloseClick(Sender: TObject);
begin
  ...
  ...
end;

I tried to introduce the procedure in the type and public
sections, but it does not work..
How do I write a handler to a created object ??
Thanks
JPI

 

Re:How do I write a handler to a runtime object


ErrClose.OnClick := ErrCloseClick;

(after you've created it, of course).

Ray

Quote
"JPI" <j...@pp.netsor.fi> wrote in message

news:Zlqd8.156$wU1.16345@read2.inet.fi...
Quote
> Hi !

> I create a Button:
> ..
> ..
> public
>     ErrClose: TButton;   {define it}
> ..
> ..

> procedure TForm1.ItAndThat;
> begin
>  ErrClose:= TButton.Create(Self);    {create the button}
> end;

> I tried to write a procedure:
> ErrCloseClick(Sender: TObject);
> begin
>   ...
>   ...
> end;

> I tried to introduce the procedure in the type and public
> sections, but it does not work..
> How do I write a handler to a created object ??
> Thanks
> JPI

Re:How do I write a handler to a runtime object


Thanks, it works !

I wonder why do I have to tell the procedure name
for my created obkect but not those I add to the
form at design time.
JPI

Quote
"Ray Cernis" <cern...@westonedesign.com> wrote in message

news:3c763672_4@news2.prserv.net...
Quote
> ErrClose.OnClick := ErrCloseClick;

> (after you've created it, of course).

Re:How do I write a handler to a runtime object


Quote
> Thanks, it works !

> I wonder why do I have to tell the procedure name
> for my created obkect but not those I add to the
> form at design time.

Because when you double-click on the TButton you've just placed on your
form, Delphi automatically assigns the handler to the OnClick event for your
button. Since there is no way to double-click run-time objects in this
fashion, you'll have to tell them what to do yourself. :)

- Samuel aka Trahojen

Other Threads