74 views
in GUI Development by
Hi!

I've a timer in Application::Application root class. I've to on and off  this timer when different Screens load. How can I call this timer in a screen which is in the same unit also in different unit?

2 Answers

0 votes
by

Hello,

if you want to have variables (e.g. to store some settings) or even a global timer 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). 

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 or a timer to the class (e.g. Counter, Volume, Timer, ....).

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.

Does this answer your question?

Best regards,

Manfred.

0 votes
by

Hello,

for this purpose first access the Application component, then access the Timer object in this component. To access the Application component exist two approaches GetRoot() method and since version 12 rootthis variable (see also Access the root object). Note, GetRoot() is available in visual components only and it returns a valid value if the component in which context the method is invoked already belongs to the view tree. rootthis is more flexible.

Additionally, during the prototyping, when you test a single component separately, there is no instance of your Application component existing. In such case GetRoot() and rootthis will return a generic Application instance used during the prototyping only. Such generic instance does not contain your Timer. Knowing this, following could be the code to access and enable a timer:

// Access the root object and try to cast it to your expected Application component
var Example::Application yourApplication = (Example::Application)rootthis;

// If the cast was successful, you can access the members of the Application and e.g.
// start a timer existing in the application:
if ( yourApplication )
  yourApplication.Timer.Enabled = true;

Best regards

Paul Banach

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

...