[fpc-pascal] C# implementation of TObject Dispatch/DefaultHandler

2010-02-02 Thread 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] C# implementation of TObject Dispatch/DefaultHandler

2010-02-02 Thread Graeme Geldenhuys
On 2 February 2010 18:49, Anthony Walter sys...@gmail.com 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  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal