Board index » delphi » Call an event from another event?

Call an event from another event?

I have two buttons on a form..  One button needs to
call the OnClick event of the other button and then
do additional processing.  When I put
button1OnClick() in Button 2's onclick event, I get
a compiler error...

Please e-mail the answer...

Jason A. Loucks
lou...@andrews.edu

 

Re:Call an event from another event?


Jason A. Loucks (lou...@andrews.edu) wrote:
: I have two buttons on a form..  One button needs to
: call the OnClick event of the other button and then
: do additional processing.  When I put
: button1OnClick() in Button 2's onclick event, I get
: a compiler error...

Jason,

This seems to work:

procedure TForm1.Button1Click(Sender: TObject);
begin
        showmessage('Button1 event');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
        showmessage('button 2 event');
        button1click(self);
end;

--
Ray Hildreth  
Greater Columbus Free-Net
rh...@freenet.columbus.oh.us

Re:Call an event from another event?


Quote
Jason A. Loucks wrote:

> I have two buttons on a form..  One button needs to
> call the OnClick event of the other button and then
> do additional processing.  When I put
> button1OnClick() in Button 2's onclick event, I get
> a compiler error...

Are you sending "Self" as a parameter?

  procedure TForm1.Button1Click(Sender: TObject);
  begin
       Button2Click(Self);
  end;

  procedure TForm1.Button2Click(Sender: TObject);
  begin
       Statusbar.Panels[0].text := 'Clicked';
  end;

Dag.

Re:Call an event from another event?


In article <31C10309.5...@sn.no>, Dag Sunde <dagsu...@sn.no> writes

Quote

>Are you sending "Self" as a parameter?

>  procedure TForm1.Button1Click(Sender: TObject);
>  begin
>       Button2Click(Self);
>  end;

>  procedure TForm1.Button2Click(Sender: TObject);
>  begin
>       Statusbar.Panels[0].text := 'Clicked';
>  end;

you can also say :

        Button2.Click;

--
Nicholas Robinson

Other Threads