How to determine which procedure to call events in delphi

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

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

Both events invoke the same procedure. I want to determine in the XYZ procedure which event triggers this (onclick or onexit), and in accordance with this we continue coding. How to determine which event will be fired? thanks

+6
source share
1 answer

You cannot obtain this 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 that determines which event is being processed.

 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; 
+11
source

Source: https://habr.com/ru/post/905503/


All Articles