Type | Description | |||
EventID as Long | A Long expression that specifies the identifier of the event. Each internal event of the control has an unique identifier. Use the EventParam(-2) to display entire information about fired event ( such as name, identifier, and properties ). The EventParam(-1) retrieves the number of parameters of fired event |
Click here to watch a movie on how you can use the eXHelper to get information about the fired events using the Event handler. The Event notification is sent any time the control fires a specified event. For instance, if the BarResize event occurs, the order of the events are Event(120) and next BarResize. You can use any of these notifications based on your requirements or limitations of the programming environment you are using.
This is useful for X++, which does not support event with parameters passed by reference. Also, this could be useful for C++ Builder or Delphi, which does not handle properly the events with parameters of VARIANT type.
In X++ the "Error executing code: FormActiveXControl (data source), method ... called with invalid parameters" occurs when handling events that have parameters passed by reference. Passed by reference, means that in the event handler, you can change the value for that parameter, and so the control will takes the new value, and use it. The X++ is NOT able to handle properly events with parameters by reference, so we have the solution.The solution is using and handling the Event notification and EventParam method., instead handling the event that gives the "invalid parameters" error executing code.
Let's assume that we need to handle the BarParentChange event to change the _Cancel parameter from false to true, which fires the "Error executing code: FormActiveXControl (data source), method onEvent_BarParentChange called with invalid parameters." We need to know the identifier of the BarParentChange event ( each event has an unique identifier and it is static, defined in the control's type library ). If you are not familiar with what a type library means just handle the Event of the control as follows:
// Notifies the application once the control fires an event. void onEvent_Event(int _EventID) { print exschedule1.EventParam(-2).toString(); }
This code allows you to display the information for each event of the control being fired as in the list bellow:
"MouseMove/-606( 1 , 0 , 145 , 36 )" VT_BSTR "BarParentChange/125( 192998632 , 'B' , 192999592 , =false )" VT_BSTR "BeforeDrawPart/54( 2 , -1962866148 , =0 , =0 , =0 , =0 , =false )" VT_BSTR "AfterDrawPart/55( 2 , -1962866148 , 0 , 0 , 0 , 0 )" VT_BSTR "MouseMove/-606( 1 , 0 , 145 , 35 )" VT_BSTR
Each line indicates an event, and the following information is provided: the name of the event, its identifier, and the list of parameters being passed to the event. The parameters that starts with = character, indicates a parameter by reference, in other words one that can changed during the event handler.
Now, we can see that the identifier for the BarParentChange event is 125, so we need to handle the Event event as:
// Notifies the application once the control fires an event. void onEvent_Event(int _EventID) { ; if ( _EventID == 125 ) /*event BarParentChange (Item as HITEM, Key as Variant, NewItem as HITEM, Cancel as Boolean) */ exschedule1.EventParam( 3 /*Cancel*/, COMVariant::createFromBoolean(true) ); }
The code checks if the BarParentChange ( _EventID == 125) event is fired, and changes the third parameter of the event to true. The definition for BarParentChange event can be consulted in the control's documentation or in the ActiveX explorer. So, anytime you need to access the original parameters for the event you should use the EventParam method that allows you to get or set a parameter. If the parameter is not passed by reference, you can not change the parameter's value.
Now, let's add some code to see a complex sample, so let's say that we need to prevent moving the bar from an item to any disabled item. So, we need to specify the Cancel parameter as not Items.EnableItem(NewItem), in other words cancels if the new parent is disabled. Shortly the code will be:
// Notifies the application once the control fires an event. void onEvent_Event(int _EventID) { ; if ( _EventID == 125 ) /*event BarParentChange (Item as HITEM, Key as Variant, NewItem as HITEM, Cancel as Boolean) */ if ( !exschedule1.Items().EnableItem( exschedule1.EventParam( 2 /*NewItem*/ ) ) ) exschedule1.EventParam( 3 /*Cancel*/, COMVariant::createFromBoolean(true) ); }
In conclusion, anytime the X++ fires the "invalid parameters." while handling an event, you can use and handle the Event notification and EventParam methods of the control
Syntax for Event event, /NET version, on:
private void Event(object sender,int EventID) { } Private Sub Event(ByVal sender As System.Object,ByVal EventID As Integer) Handles Event End Sub |
private void Event(object sender, AxEXSCHEDULELib._IScheduleEvents_EventEvent e) { } void OnEvent(long EventID) { } void __fastcall Event(TObject *Sender,long EventID) { } procedure Event(ASender: TObject; EventID : Integer); begin end; procedure Event(sender: System.Object; e: AxEXSCHEDULELib._IScheduleEvents_EventEvent); begin end; begin event Event(long EventID) end event Event Private Sub Event(ByVal sender As System.Object, ByVal e As AxEXSCHEDULELib._IScheduleEvents_EventEvent) Handles Event End Sub Private Sub Event(ByVal EventID As Long) End Sub Private Sub Event(ByVal EventID As Long) End Sub LPARAMETERS EventID PROCEDURE OnEvent(oSchedule,EventID) RETURN |
<SCRIPT EVENT="Event(EventID)" LANGUAGE="JScript"> </SCRIPT> <SCRIPT LANGUAGE="VBScript"> Function Event(EventID) End Function </SCRIPT> Procedure OnComEvent Integer llEventID Forward Send OnComEvent llEventID End_Procedure METHOD OCX_Event(EventID) CLASS MainDialog RETURN NIL void onEvent_Event(int _EventID) { } function Event as v (EventID as N) end function function nativeObject_Event(EventID) return |