Board index » delphi » Runtime "onclick" handler assign for menus

Runtime "onclick" handler assign for menus

Anybody knows how I could assign a procedure as an onclick handler for
a menuitem in RUNTIME ? Anyhow, "onclick:=procedurename;" does not
work ...
Thank you for your time,
John Iliadis

 

Re:Runtime "onclick" handler assign for menus


Quote
teii...@prometheus.hol.gr wrote:
> Anybody knows how I could assign a procedure as an onclick handler for
> a menuitem in RUNTIME ? Anyhow, "onclick:=procedurename;" does not
> work ...

Yes it does.  This code is off the cuff, so may have some errors, but is
generally what you need.  For a complete example, get my TMRUFileList
component at http://www.pobox.com/~bstowers/delphi/.  It assigns OnClick
handlers at runtime.

type
  TMyForm = class(TForm)
    {...}
  public {or private if you prefer}
    procedure OnMenuClick(Sender: TObject);
    {...}
  end;

{...}

procedure TMyForm.OnMenuClick(Sender: TObject);
begin
  { do your thing here }
end;

{ In whatever procedure/event handler you need to use }
  MyMenuItem.OnClick := OnMenuClick;
end;

Regards,
Brad
bstow...@pobox.com
Free Delphi Stuff:  http://www.pobox.com/~bstowers/delphi/

Other Threads