195 views
in GUI Development by
Accessing a slot of another class
it is possible to instantiate a method of another class in the class where I need it
in my case I have a Zone class and I want to take the slotmethod OnContactZone because I have the logic I need:

if (GetLedStatus(0) && !GetLedStatus(1) && !GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 0 ; //summer

if (!GetLedStatus(0) && GetLedStatus(1) && !GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 1; //winter

if (!GetLedStatus(0) && !GetLedStatus(1) && GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 2 ;//holiday

in the class where I want to invoke it I have my UpdateSpecialLed slot

if (GetLedStatus(0) && !GetLedStatus(1) && !GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 0 ; //summer

if (!GetLedStatus(0) && GetLedStatus(1) && !GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 1; //winter

if (!GetLedStatus(0) && !GetLedStatus(1) && GetLedStatus(2))
  tmScreenMain::GlobalVariable.Season = 2 ;//holiday

is it possible to make a call or to integrate it into the condition? Because if I create a variable in which I instantiate the class like: var Synoptic1000::Zone and write

Zone.OnContactZone () I get:
[15.7.2024 13:13:04] Error tmScreenMain::HomePage.UpdateSpecialLed (50:6) : Unknown method 'OnContactZone()' called in scope of the class 'Synoptic1000::Zone'.

Translated with DeepL.com (free version)

1 Answer

0 votes
by

Hello,

accessing members of a class is possible only in context of an instance of this class, not the class itself. For example you could instantiate the class temporarily and use it in place:

( new Synoptic1000::Zone ).OnContactZone();

Other approach is to add an autoobject of the class Synoptic1000::Zone. Then use this autoobject to access the slot method.

Please note: autoobjects are global entities which are created on demand and released if not used anymore. In worse case this may have the effect of the autoobject being instantiated temporarily each time you access its member. Possibly, much more simple would be to copy the implementation of the affected method to the class where it is needed.

Best regards

Paul Banach

by

Sure, here's your revised and translated question in English:


In my Embedded Wizard project, I have an object called Type, and I want it to change colors depending on the seasons. In tmScreenMain::HomePage, I have a slot where I implemented the logic necessary for my hardware to understand the seasons:

 

plaintext

Copia codice

$if $prototyper trace ("UpdateSpecialLed"); $endif var int32 noOfItems = Outline.CountViews(); var tmScreenMain::BtnText item; var int32 i; $if $prototyper // Iterate all items in the LedStatusSim array. Simulate the LED state change. // If an LED is off (0), it is turned on (1), and if it is on, it is turned off. for ( i = 0; i < LedStatusSim.size; i = i + 1 ) { if (LedStatusSim[i] == 0) LedStatusSim[i] = 1; else LedStatusSim[i] = 0; } $endif // lcounter keeps track of the number of LEDs handled, ignoring vertical lines. var int32 lcounter = 0; for ( i = 0; i < noOfItems; i = i + 1 ) { // Get the current item item = (tmScreenMain::BtnText) Outline.GetViewAtIndex( i ); if ( item != null ) { item.Bounds.h = Outline.Bounds.h; item.Visible = GetLedStatus( /*i - 1*/ lcounter ) && ( item.FrameNumber != 0 ); // Added the final part to hide the special LED if FrameNumber = 0 item.Enabled = GetLedStatus( /*i - 1*/ lcounter ) && ( item.FrameNumber != 0 ); // Handling vertical lines var Views::Line ln = (Views::Line) Outline.GetViewAtIndex( i + 1 ); if ( ln != null ) { ln.Visible = item.Visible; } lcounter = lcounter + 1; } } if (GetLedStatus(0) && !GetLedStatus(1) && !GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season = 0; // summer } else if (!GetLedStatus(0) && GetLedStatus(1) && !GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season= 1; // winter } else if (!GetLedStatus(0) && !GetLedStatus(1) && GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season = 2; // holiday }

Then in Synoptic::Zone, I have a property ^int16 ContactZone.

 

plaintext

Copia codice

OnSetContactZone: // Check if the new Temperature differs from the currently used Temperature if ( pure ContactZone == value ) return; // Detach from the previous Temperature if ( pure ContactZone != null ) detachobserver OnContactZone, pure ContactZone; // Store the new Temperature ... pure ContactZone = value; // ... and attach to the new one if ( value != null ) attachobserver OnContactZone, value; // Finally, retrieve the current state of the property associated via 'Temperature'. //if ( value != null ) postsignal OnContactZone;

After that, I implemented a slot to manage the color of the Type object based on the season:

 

plaintext

Copia codice

if (ContactZone == null){ return; } if (ContactZone^ == 0 ) Type.Color = Res::color10; else{ if (tmScreenMain::GlobalVariable.Season == 0 ) Type.Color = Res::color09; // summer else if (tmScreenMain::GlobalVariable.Season == 1 ) Type.Color = Res::color02; // winter else if (tmScreenMain::GlobalVariable.Season == 2) Type.Color = Res::color10; // holiday }

Initially, this approach works, but if I try to change the season without first turning the potentiometer off and on, the color of Type does not change, and I have to power cycle the potentiometer.

I was thinking of using a property observer or creating an event, but I don't know how to proceed.

by
I'm sorry but I can't read the code from your comment.
by
i fix it Thank you anyway!

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

...