DefaultHandler (Delphi)
Description
This code example is a Delphi Forms Application that illustrates the usage of the DefaultHandler method.
Code
The following code listing contains the definition of a custom edit box class: TMyEdit. This is necessary to override the DefaultHandler method.
type
TMyEdit = class(TEdit)
public
procedure DefaultHandler(var Message); override;
end;
The DefaultHandler method in TMyEdit shows a message box every time a key is pressed into a TMyEdit instance:
procedure TMyEdit.DefaultHandler(var Message);
begin
if TMessage(Message).Msg = WM_KEYUP then
ShowMessage('No callback is associated with WM_KEYUP messages for LMyEdit instance');
inherited;
end;
When the main form is created, an instance of TMyEdit is created and placed on it:
procedure TForm1.FormCreate(Sender: TObject);
var
LMyEdit: TMyEdit;
begin
LMyEdit := TMyEdit.Create(Self);
LMyEdit.Left := 6;
LMyEdit.Top := 8;
LMyEdit.Visible := True;
LMyEdit.Parent := Self;
end;