How Do I Raise a Dynamically Named Event? (Magic xpa 3.x)
There might be occasions where you want to raise an event using its text name. This might be the case, for instance, if you are raising an event in the host program from a component: you cannot just select the event because it is not in scope. Or, you might want to select between various events based on user input, or store the event name in a table.
In our example, we allow the user to choose the event from a list of events, then execute the chosen event.
Before you can call a dynamically-named event, you must set up the event in the Main Program, and give it a Public Name. Here we have our events: Chat, Send, Receive, and LogCall.
Next, you need to call the event.
-
Go to the location where you want to raise the event.
-
Type R to create a Raise Event operation. The Event box will appear.
-
Go to the Event Type field. Select Public Event.
-
Go to the Event field. Zoom to enter an expression. Make that expression evaluate to the exact name of the event (case matters, as do trailing spaces).
In our example, the user chooses an item from a list, which happens to be the exact name of the event. We just trim the spaces off it and raise it as a Public Event.
The Online and Rich Client Samples projects (program EH08 and REH08)