When writing components, you should not use event handlers to implement custom behavior. Instead, you should override the code that calls these event handlers. In this case, forget about setting OnClick . Instead, just add
public procedure Click; override;
into the class declaration and implement
procedure TLoginButton.Click; begin inherited; // call the inherited Click method. // Do something new. end;
Event handlers must be used by the developer using the component. The component writer should not use them on their own.
If you want the component user to see another OnClick method, you must implement this yourself, for example
type TLoginResultEvent = procedure(Sender: TObject; LoginResult: boolean) of object; ... TLoginButton = class(TButton) private FOnClick: TLoginResultEvent; ... public procedure Click; override; ... published property OnClick: TLoginResultEvent read FOnClick write FOnClick; ... procedure TLoginButton.Click; begin inherited; if Assigned(FOnClick) then FOnClick(Self, true); // or false... end;
source share