So I have this class, lets call it Foo, and I have an event in this class named Bar.
In C# you'd do something like:
public partial class Foo : UserControl {
public delegate void FooEventHandler(object sender, FooEventArgs args); public event FooEventHandler Bar; private void DoStuff() {
FooEventArgs args = new FooEventArgs(15);
this.Bar(this, args)
}
} public class FooEventArgs : System.EventArgs { public FooEventArgs(int wut) { this.Wuut = wut; } public int Wuut; }
In ABL you.. Well that's kinda the point, I don't know. The documentation is pretty vague with defining own delegates and events, but I did kinda accomplish creating an own event:
CLASS Foo INHERITS UserControl:
DEFINE PUBLIC EVENT Bar SIGNATURE VOID (Sender AS System.Object, Args AS FooEventArgs).
METHOD PUBLIC VOID DoStuff():
DEFINE VARIABLE args AS FooEventArgs NO-UNDO.
args = NEW FooEventArgs(15).
THIS-OBJECT:Bar:Publish(args).
END METHOD.
END CLASS.
CLASS FooEventArgs INHERITS System.EventArgs:
CONSTRUCTOR PUBLIC FooEventArgs(wut AS INTEGER):
THIS-OBJECT:Wuut = wut.
END CONSTRUCTOR.
DEFINE PUBLIC VARIABLE Wuut AS INTEGER NO-UNDO.
END CLASS.
This passes syntax checking at least, but I haven't been able to test it yet, since there is so much more code for me to implement before I would be able to test it at all. Also, there is an issue: This event does NOT show up in the Eventlist in OE Architect Visual Designer, when I create a new Form and drag a Foo onto it! Also, is publish really the way to go? Won't I need an eventhandler/delegate? Please fill me in!
EDIT: To clear stuff up, the event shows up in the autocompletion-list (ctrl+space), and it is there as an event. If i try to call it directly using THIS-OBJECT:Bar(args). It nags about it not being found at all. But it doesn't show up in the visual designers eventlist.
What I'm using:
ABL in OpenEdge Architect 10.2B02
the code looks right - but doesn't pass syntax check because you are only passing 1 parameter to the event, but declaring two in the event definition
This sets up the event.
Internally, you could just call the DoStuff() method. You should also call the method externally as well.
to subscribe, check out the subscribe method
You must also ensure that you unsubscribe any event that you subscribe to, as the subscription is not automatically cancelled by the garbage collector, which can lead to memory leaks.
In order for an event to show up in the Visual Designer you must create is as a delegate like so:
DEFINE PUBLIC EVENT Bar DELEGATE System.EventHandler.
-peter
Thank you! There is a wrong in the code I posted, I noticed this now. Wrote it directly in this textbox hehe.
Allright thanks a lot! Can I create my own delegate/eventhandler, or would it still work with my custom arguments?
Great response btw!
You can extend your arguments as long as they inherit from System.Object and System.EventArgs.
-peter
Allright thanks a lot! Can I create my own delegate/eventhandler, or would it still work with my custom arguments?
You cannot define a delegate from ABL.
But you can create your own .NET assembly holding your own delegates and custom EventArgs classes.
Or use the default System.Delegate. You can still pass child classes of System.EventArgs as an argument - but the signature will be a System.EventArgs - so you'll have to CAST it in the event handler method to access your custom properties.
Using these lines, first one in class declaration, second one in classmethod, still wont show up in OE Architect Visual Designer. I can subscribe to it successfully and parse the eventarguments (casting them), but nothing in Visual Designers Eventlist. This isn't a huge issue but I still would like it to work!
DEFINE PUBLIC EVENT GuruAfterDropped DELEGATE System.EventHandler.
DEFINE VARIABLE args AS Controls.Subclasses.DragDropArgs NO-UNDO.
args = NEW Controls.Subclasses.DragDropArgs(Dragger, Dragger:Selected:Rows).
THIS-OBJECT:GuruAfterDropped:Publish(THIS-OBJECT, CAST(args, System.EventArgs)).
Thanks for the superfast response everybody!
Nevermind a restart of OE did the trick! Again, thanks!
Thanks! Very helpful! Did the trick!
[sorry the quote button does not work on the system I am currently working on]
> Or use the default System.Delegate. You can still pass child classes of System.EventArgs as an argument - but the signature will be a System.EventArgs - so you'll have to CAST it in the event handler method to access your custom properties.
Actually you can. We do it all the time:
AfterToolEnable:
Publish(THIS-OBJECT, NEW base.client.control.toolbar.aftertoolenableeventargs(otool#)).
METHOD PRIVATE VOID ToolbarsManager_AfterToolEnable(INPUT sender AS System.Object, INPUT e AS base.client.control.toolbar.aftertoolenableeventargs):