I use a kind of Software Bus, introduced by N. Wirth in his Programming on Oberon. The idea is in object-oriented (actually extensible record-oriented in the original) message system:
Code:
TMessage = class // Base message class
end;
CMessage = class of TMessage;
TMessageHandler = procedure(const Msg: TMessage) of object;
...
TWindowResizeMsg = class(TMessage) // Example: this message is sent by window manager when its size changes
OldWidth, OldHeight, NewWidth, NewHeight: Single;
constructor Create(AOldWidth, AOldHeight, ANewWidth, ANewHeight: Single);
end;
...
procedure TRenderer.HandleMessage(const Msg: TMessage);
begin
...
if Msg.ClassType = TWindowResizeMsg then with WindowResizeMsg(Msg) do begin
... // handle window size change
end end else if Msg.ClassType = TWindowMoveMsg then ...
end;
You can register a chain of message handlers (TMessageHandler) and handle (or ignore) within them any message of any kind. All parameters needed (also any number of any kind) are incapsulated in a message class. This is really secure and useful.
In Delphi you have to use a chains of annoying if-then-else operators. In Oberon the WITH operator is acting like the CASE operator in Delphi but for testing classes and used for software bus. Also the IS operator in Oberon takes just one operation to perform the test. But CodeGear don't care at all. :evil:
In Delphi we have class helpers and other useless stuff instead. :evil:
UPD: I forgot about sending code.
In OS message handler:
Code:
...
function WindowProc(WHandle: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
...
case Msg of
...
WM_SIZE: if wParam = SIZE_MINIMIZED then
Core.HandleMessage(TWindowMinimizeMsg.Create) else
Core.HandleMessage(TWindowResizeMsg.Create(0, 0, lParam and 65535, lParam shr 16));
Core.HandleMessage will deliver the messages where needed.
Bookmarks