[fpc-pascal] C# implementation of TObject Dispatch/DefaultHandler
sysrpl at gmail.com
Tue Feb 2 17:49:24 CET 2010
I though I'd share this and as for any feedback.
Today I was experimenting with a borrowing a Delphi concept and
implementing it in C#. I wanted to be able to do this in C#:
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
And I believe I came up with a similar yet workable enough solution to
doing the same thin in C#. Here is what the C# code looks like:
private void MouseMove(Type type, Message message)
// message handling code here
Where "incommingMessage" is a message or message derived object, and
instance is a "DispatchObject".
Mind you, I am doing a few things here.
1) Dispatch calls only the most derived method with the matching message id.
2) The name of the method "MouseMove" is irrelevent. The id is used to
find the method.
3) Inherited message handlers can be invoked through the protected
4) If no methods with a matching id are found, the virtual
"DefaultHandler" method is called.
Source code listing: http://codebot.org/dispatch.txt
More information about the fpc-pascal