You can use PowerScript to dynamically connect methods to .NET events.
You can connect single or multiple methods to a .NET event in PowerScript. The method could be a PowerBuilder global function, an instance function of a PowerBuilder object, or an instance or static function of a .NET object. You can also connect PowerBuilder events to .NET events in PowerScript.
You are not able to declare a variable or a parameter with a .NET event because a .NET event is not a type at all. You are also not able to declare a new .NET event in PowerBuilder code; you can only consume a .NET event defined in other .NET languages with the += operator in PowerBuilder.
The following examples demonstrate how to dynamically hook up to a .NET event in PowerScript.
'Clicked' is a .NET event defined in the third-party .NET control 'system.windows.controls.button'. Suppose 'OnClick1' is a PowerBuilder event that has exact same signature as the 'Clicked' .NET event of 'System.Windows.Controls.Button' control. With this enhancement, you can support the following use cases.
Event OnClick1(system.object sender, RouteEventArgs e)
System.Windows.Controls.Button cb1 cb1 = create System.Windows.Controls.Button() cb1.clicked += OnClick1
System.Windows.Controls.Button b b = cb_1.InnerControl b.Click += OnClick1