Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-02

C# implementation of TObject Dispatch/DefaultHandler

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

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:

[Message(Messages.MouseMove)]
private void MouseMove(Type type, Message message) {

  BaseHandler(type, message);
  // message handling code here

}

Invocation:

instance.Dispatch(incommingMessage);

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 "BaseHandler" method.
4) If no methods with a matching id are found, the virtual "DefaultHandler" method is called.

Source code listing: http://codebot.org/dispatch.txt

Reply by email

Jonas Maebe
to Anthony Walter
Anthony Walter wrote
I though I'd share this and as for any feedback.

Since this does not appear to be about programming in FPC (nor about interoperating with FPC/Delphi code), the fpc-other mailing list would be more appropriate for this discussion. Please post follow-ups there.

Thanks,

Jonas
FPC mailing lists admin

Reply by email