248 views
in Embedded Wizard Studio by
Hello,

I am figuring out how to use BroadcastEvent method but I am not able to find  examples that show how to use it or what the typical scenario is.

Best regards,

Marco

1 Answer

0 votes
by

Hello Marco,

BroadcastEvent() exists mainly for compatibility purpose with older versions. It has a disadvantage of notifying only views which are part of the view tree. Today I would recommend to use the System Event and System Event Handler as infrastructure to propagate notifications. Unlike BroadcastEvent() this technique is also able to notify objects which are not part of view tree. Although the mentioned documentation addresses the usage of System Event to handle event generated by the device, this approach can also be used to handle events generated locally in the UI. See also Trigger System Events locally from Chora code.

If you nevertheless want to use the BroadcastEvent() approach, following are the necessary steps:

Step 1: Implement your own Event class. This class has to descend from Core::Event. Inside your class you can add data members, e.g. variables, etc., where information associated with the event can be stored.

Step 2: To broadcast the event, create an instance of your class (step 1), initialize its variables with data you want to send with the event and pass the instance to BroadcastEvent() method. For example:

var Application::Event event = new Application::Event;

event.Data = "Some text to provide with the event.";

rootthis.BroadcastEvent( event, Core::ViewState[]);

Step 3: To react to the event, in the affected component override the method HandleEvent() and implement it as shown below:

// Invoke the inherited version of the method 'HandleEvent'.
// Remove the line if the inherited code should not be executed.
var object result = super( aEvent );

// Try to cast the event object to your event class.
var Application::Event event = (Application::Event)aEvent;

// If the received event object is of your event class, handle the event.
if ( event )
{
  trace event.Data;
}

// Return the result of the operation.
return result;

I hope it helps you further.

Best regards

Paul Banach

by
Hello Paul,

i did as you wrote me but something is not clear to me.

First, EW studio version is 13.

I create a variant of the class Event in the Application unit, called TestEvent. Then, I overridded the method HandleEvent() but I am not able to recall my TestEvent. Why?

Regards,

Marco
by
With "recall" I mean that it is not possibile to write Application::TestEvent.

I override the method HandleEvent() for the component ItemLarge and compile with the following Error.

[3.10.2025  9:46:50] Error Home::ItemLarge.HandleEvent (19:5) : Unknown definition 'Application::TestEvent' found.
by
It was my mistake. I managed to implement my TestEvent as a derived class and not as variant.

Will BroadcastEvent() exist also in future version?

Currently my purpose is notifying only views which are part of the  view tree. Do you think SystemHandler and SystemEvent are still better than BroadcastEvent?

Regards,

Marco
by

Hello Marco,

Will BroadcastEvent() exist also in future version?

We have not planed to remove it. Too many older applications depends on this method.

Currently my purpose is notifying only views which are part of the  view tree. Do you think SystemHandler and SystemEvent are still better than BroadcastEvent?

If you have a working version based on BroadcastEvent() then I would stay with this version. System Event and Handler are just a more convenient and flexible approach.

Best regards

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...