C# implementation of TObject Dispatch/DefaultHandler

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

C# implementation of TObject Dispatch/DefaultHandler

Anthony Walter-3
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: C# implementation of TObject Dispatch/DefaultHandler

Jonas Maebe-2

On 02 Feb 2010, at 17:49, 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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: C# implementation of TObject Dispatch/DefaultHandler

Graeme Geldenhuys-2
In reply to this post by Anthony Walter-3
On 2 February 2010 18:49, Anthony Walter <[hidden email]> wrote:
> I though I'd share this and as for any feedback.

Wrong mailing list, this list is about Object Pascal.



--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal