Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to determine which event calls procedure in delphi

Tags:

delphi

I have a procedure named XYZ(sender:TObject) in delphi. There is one button on my form.

Button.onclick:= xyz;
Button.OnExit:= xyz;

Both the events calls the same procedure. I want to determine in procedure XYZ, which event calls this(onclick or onexit) and according to that proceed with coding. How to determine which event gets fired? thanks

like image 889
Nalu Avatar asked Jan 09 '12 09:01

Nalu


1 Answers

You can't get hold of that information by fair means. The solution is to use two separate top-level event handlers which in turn can call another method passing a parameter identifying which event is being handled.

type
  TButtonEventType = (beOnClick, beOnExit);

procedure TMyForm.ButtonClick(Sender: TObject);
begin
  HandleButtenEvent(beOnClick);
end;

procedure TMyForm.ButtonExit(Sender: TObject);
begin
  HandleButtenEvent(beOnExit);
end;

procedure TMyForm.HandleButtonEvent(EventType: TButtonEventType);
begin
  //use EventType to decide how to handle this
end;
like image 129
David Heffernan Avatar answered Oct 15 '22 06:10

David Heffernan