38 views
in Getting started by

I assume this is not a bug, but merely a gap in my understanding, however I would love someone to eplain this detail, which to me seems inexplicable.

This is the contects of WidgetSet::RadioButton.Outlet

// Check if the new outlet differs from the currently used outlet
if ( pure Outlet == value )
  return;

// Detach from the previous outlet
if ( pure Outlet != null )
  detachobserver onOutlet, pure Outlet;

// Store the new outlet ...
pure Outlet = value;

// ... and attach to the new one
if ( value != null )
  attachobserver onOutlet, value;

// Finally, retrieve the current state of the property associated via 'Outlet'.
if ( value != null )
  signal onOutlet;

My question concerns the line in bold, "attachobserver onOutlet, value".

Why have we written this and not "attachobserver onOutlet, pure Outlet"? I understand that "value" is in some sense a pointer to a place is memory, and attachobserver is assigning onOutlet to listen for changes in this value. But that doesn't really explain why we can do this with "value", when I thought "value" would have been defined only in the scope of this method, or why we do this when it looks like EW has syntax for binding to Properties too. https://doc.embedded-wizard.de/attachobserver-statement?v=14.00

It is possible that I am coming at this from too much of a C++ background, but any illumination would be appreciated here.

1 Answer

0 votes
by

Hello,

this is not a bug.

attachobservers onOutlet, value and attachobserver onOutlet, pure Outlet have the same effect. Note the line pure Outlet = value. Both data members are equal.

The difference is, value is a local variable while pure Outlet is a variable existing in the object. Accessing pure Outlet is minimally more CPU intensive. It is the author's preference to use this implementation.

On the contrary, detachobserver onOutlet, pure Outlet is without alternative. This is because pure Outlet is the unique location where the old reference is stored to detach the observer.

From technical point of view, the local variable value as well as the object variable Outlet store so-called property reference. It can be compared to a pointer in C.

I hope it helps you further.

Best regards

Paul Banach

by
That makes a lot of sense, thank you so much for the clarification!

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...