In the absence of OOP - which I understand, based on the model - it would still be nice to have delegates that can match particular actions, and that a delegate type could be a parameter for an action.

I actually made an attempt at making delegates/callbacks (attached) but late in the process, I got a rather stern lesson about how bad reflection is at handling structs in .NET.

I made it so that you could make a Structure with exactly the same layout as the Actions you were expecting to call, e.g.

...and then an example Action with those same parameters:

Then I had the actual Callbacks - here was my sample flow:

CreateCallback took the ESpace and the name of the Structure:

You could choose which Action to bind the Callback to via BindCallback:

Make a local variable of the Structure type and assign parameters to it:

...and then call the actual Callback with those parameters:

It almost worked. I could read things out of the parameters, and the breakpoint in TestEmailCallback got hit:

I couldn't get the results back, though. The ToObject(parameters) makes a boxed copy of the structure, and FieldInfo.SetValue(structure, value) actually makes a boxed copy of the structure every time it sets the field, and so loses the field.

There's __makeref and SetValueDirect and weird things like that, but absent being able to do that from the OutSystems side or being able to convert a generic object to a specific structure, I think I will have to abandon my efforts - or maybe thing of a less-cool way of doing it.

Anyhow, I'd like this as an OutSystems feature at some point so that I don't have to do weird things with Switches everywhere :)

Also, sorry for being a bit insane.

-- Ritchie Annand

Created on 25 Apr
Comments (3)

Changed the category to Backend

What would be the advantage?

Same as delegates in other languages - you can pass in a comparison action or a factory action or an event listener action.

It's not as though there's no way to do it now - you can make actions that, say, take a static entity ID or text or an integer and throw things through a switch statement, but it does limit the functionality you can put in separate modules and it can be a bit of a maintenance headache.

Tiago's been showing us "the OutSystems way" of splitting up modules into a more visual-focused MyModule and a more data and services-focused MyModule_Core, but anything that needs something like a delegate basically has to stay in the same module as what it needs to call back to right now.

Might make for more consistent "event actions", like On Row Save or On Change being able to be assigned directly or to a delegate.