Quick start manual
7-16
Delphi Language Guide
Methods
the Messages unit. A message method must be a procedure that takes a single var
parameter.
For example, on Windows:
type
TTextBox = class(TCustomControl)
private
procedure WMChar(var Message: TWMChar); message WM_CHAR;
ƒ
end;
For example, on Linux or for cross-platform programming, you would handle
messages as follows:
const
ID_REFRESH = $0001;
type
TTextBox = class(TCustomControl)
private
procedure Refresh(var Message: TMessageRecordType); message ID_REFRESH;
ƒ
end;
A message method does not have to include the override directive to override an
inherited message method. In fact, it doesn’t have to specify the same method name
or parameter type as the method it overrides. The message ID alone determines
which message the method responds to and whether it is an override.
Implementing message methods
The implementation of a message method can call the inherited message method, as
in this Windows-specific example:
procedure TTextBox.WMChar(var Message: TWMChar);
begin
if Message.CharCode = Ord(#13) then
ProcessEnter
else
inherited;
end;
On Linux or for cross-platform programming, you would write the same example as
follows:
procedure TTextBox.Refresh(var Message: TMessageRecordType);
begin
if Chr(Message.Code) = #13 then
...
else
inherited;
end;
The inherited statement searches backward through the class hierarchy and invokes
the first message method with the same ID as the current method, automatically
passing the message record to it. If no ancestor class implements a message method