698 views
in GUI Development by
Hi,

   i need to create global variable and i want to access that variable from anywhere.

i referred documenation  : https://doc.embedded-wizard.de/autoobject-member?v=11.00

i have created autoobject class also.next wt i do.how to assign varible and how to access from other class

i need brief explanation.please share it.

1 Answer

0 votes
by

Hi,

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.

You can do 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 variableset 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 clear....

Best regards,

Manfred.

by
Hi Manfred,

Thanks for the brief explanation.i follwed the same but i am getting error mentioned below.how to clear this

Error : Endless recursion detected in the initialization of the auto object 'Application::GlobalSettings'. As long as an auto object is performing its initialization, no recursive accesses to this object are possible.
Runtime Application::Settings.Lastname (1:1) : The auto object is not available.
by
Hi,

according to the error message, you try to access an object during its initialization. Based on the provided information it is difficult to give helpful advices.

Please have a look to the provided examples - many of them contains a DeviceClass that stores global values that are accessed from different locations of the application.

Hope this helps...
by
Deviceclass is just class name correct ?

my class name is Settings.i think class name is not a issue.please help me to resolve this.
by
The class name is not important. Have you seen all the links in my first answer? Please follow the detailed description.

If there is still an error message, please provide more details.
by
I have 2 screen .i want to transfer data from one screeen to another.so  2nd form  i am creating global  varibale and assign the value:

Application::GlobalSettings.Lastname =   LastnameTextEditor.String;  //it is string value
Application::GlobalSettings.Firstname=FirstnameTextEditor.String;  //it is string value
Application::GlobalSettings.Id=Id.String;  //it is string value

 

i am facing this error:

Can not cast from type 'string' to type 'Application::Settings' in the assignment.
 The both types are not compatible. No automatic conversion possible.

how to clear this issue.how to convert string to object.
by

Without seeing the whole context, I cannot detect the reason. I assume that the type of the Property Lastname or Firstname is not a String. Thus you get the error message that the 'string' cannot be casted to type 'Application::Settings' in the assignment.

by
i am creating small form .i have 3 textbox.i am getting value from text box and try to assign global variable

global variable object type.so  it is throwing error.

string not assign to object data type variable

this is our problem
by
Can you post a screenshot of the class Application::GlobalSettings?
by

https://ask.embedded-wizard.de/?qa=blob&qa_blobid=101114969670146461

 

here i have mentioned my updates.please check it

by

According to your screenshot, the type of the property Lastname is Application::Setting - but it should be String in order to store a string. Then you can make the following assignment:

Application::GlobalSettings.Lastname =   LastnameTextEditor.String;  //it is string value

Same for Firstname and Id.

by

Hi  Manfred Schweyer,

Thank you for your suggestions.I have apply changes.

With Regards,

Ramesh.G

by
Hi Gururamesh,

I also doing same concept but I am not getting the desired result. Can you please guide me how you did it?

Regards

Rangsons

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

...