One eventhandler for many objects in array, how to identify

Posted by Stefan Marquardt on 03-May-2012 09:26

I am just think about defining an array of objects from an external assemby and register one handler for every one.

That should not be the problem.
But i need to identify the extent of the array in the handler, which object has fired the event.

Is this possible with ABL.NET?

For C# i find something like this there i can forward the parameters to an anonymous handler with adding own arguments like the extent number for identifying in the handler.

button1.Click += (p,c) => doSth(p,c,"arg", "s...");

Actual code:

define variable oObject as Object no-undo extent 3 init ?.

oObject[iObject]:DataEvent:Subscribe(DataEventHandler).

Stefan

All Replies

Posted by Admin on 03-May-2012 09:37

GUI for .NET events and their handlers need to follow the .NET standard (in .NET it's just a standard, for GUI for .NET it's a must) an have two parameters:

1) A System.Object (typically the sender)

2) A Sytem.EventArgs or derived type

So when you need to know which Object from your array of objects has raised the event, you should know the reference to the sender from the first parameter.

If you need to know the Index (position), and not the reference itself, something like this should work

iIndex = Sytem.Array:IndexOf (oYourArray, sender).

If you can modify the event code on the .NET side, you can create your own System.EventArgs derived type and pass that as the second parameter and tell the event handler so whatever you desire (current temperature in Soltau + your desired temperature in Soltau + the index of the sender in the array).

Posted by Stefan Marquardt on 04-May-2012 01:24

Thanks for the very fast answer.
It works with the "trick" that the returned value has to be +1 for the ABL array.

Posted by Admin on 04-May-2012 01:32

Not a trick for me, just the way things are designed....

This thread is closed