how to add global variable in GUI

22 views
asked Oct 9 in Embedded Wizard Studio by chand bhadaniya
Hi Users,

 

I want to use a global variable, which i can access from all dialogs(screens). how to make variable globle ?

 

Thanks,

chand bhadaniya

1 Answer

0 votes
answered Oct 9 by Manfred Schweyer
 
Best answer

Hi Chand Bhadaniya,

if you want to have variables (e.g. to store some settings) that should be accessible from different components within your applications, you can put these variables into a separate class and create an autoobject of this class (e.g. Application::Settings). Instead of variables you can use properties - then you can additionally use notifications and observers to inform your GUI components about changes within the settings class.

Best regards,

Manfred. 

commented 5 days ago by chand bhadaniya
Hi Manfred,

 

I tried to do what you say but i didn't get any result.

Can you please elaborate answer or give any example project.

 

Thanks,

Chand Bhadaniya
commented 3 days ago by Manfred Schweyer

Hi, please try the following:

Add a new class to your unit (e.g. Application) and rename it to Settings.

Open the class Settings and add your Properties to the class (e.g. Counter, Volume, ....).

Now, create an autoobject of the class Settings within the unit Application and rename it to GlobalSettings.

Within your application class, create a variable, set the type to Application::Settings and set the initialization value to Application::Globals. This ensures that your global class is kept within the memory the whole runtime of the application.

Now you can access your global properties from everywhere in the GUI application, e.g.

Application::GlobalSettings.Volume = 5;

Application::GlobalSettings.Counter = 0;

Hope this makes it more clear now....

Best regards,

Manfred.

commented 3 days ago by chand bhadaniya
Hi Manfred,

 

Thanks for your valuable replay.

It solves my issue.

 

Thanks,

Chand Bhadaniya

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

...