37 views
in System Integration by
How do I override getCurrentTime() for Core:Time ?

1 Answer

0 votes
by

Hello Mike,

if you have derived a new class from Core::Time, you can override in this new class all inherited methods similarly to how you override any other method. For this purpose see Override an inherited method. Consequently, this will affect the derived class only.

If you want to modify the method getCurrentTime in the original class Core::Time, so it has 'global' effect for all instances of Core::Time, you have to override the class Core::Time by a class variant. Within the class variant you can then override the method getCurrentTime. This modification will affect the original Core::Time 'retrospectively'.

Please note, the method getCurrentTime() is an internal method used also at the prototyping time. Modifying it may have a negative effect on the application. Do you have concrete reasons to do this?

Best regards

Paul Banach

by
Thanks Paul,

 Yes, I need to modify so WebGL pulls our RTC instead of the local OS time:

 

$if !$prototyper && ( $platform == *.WebGL.* )
/*   mls
  native ( result )
  {
    result = (( new Date ).getTime() / 1000 ) | 0;
  }
*/
  result = Application::Device.HMI_time; // mls

$endif
by

Hello Mike,

in such case the second approach using the class variant would be suitable. Nevertheless, the JavaScript function getTime is used often in other classes. You would need to adapt all those classes.

Best regards

Paul Banach

by

I'm a bit lost.... I created the Variant:

 

And modified the getCurrentTime() method:

 

BUT, when I try and access it via Application:: I cant...????

by

Hi Mike,

The variant affects the original class Core::Time. So you still continue using Core::Time. The variant itself (e.g. Application::Time_V) can't be used directly.

Does it help you?

Best regards

Paul Banach

by
I cant seem to access Application::Time though. Do I need to create a Core::Time block in each of my classes that need it? And then access it locally, say, like StatusBar_Time::CurrentTime ?

I guess I'm confused because I had been using a Application::Time that was available globally.
by
I'm confused too. How do you use the Time class?
by

To better understand your application case, do you need the RTC time in the entire application, means wherever Core::Time is used? Or just in few particular cases?

by
I need access to Time.CurrentTime in the entire application.
by

I think I got it. If I drag over Core::Time into my Application unit it creates a class block. But if I do this same drag and drop in a dialog class it creates the Time autoobject block.

So i cut and pasted the autoobject from the dialog class into the Application unit.  ...why does it work this way?

 

by

Hi Mike,

Drag&Drop is a very powerful technique to create copies of classes, derive classes, derive variants of classes and create instances of classes. All with a single Drag&Drop operation. The default result of the operation depends primarily on the target where you drop something. Concrete:

- If you drop a class within a unit, a copy of the class is created.

- If you drop the class within another class (e.g. GUI component) an instance of the class is created. This is because, classes can't exist within another class. 

This default behavior can additionally be controlled by pressing the keys CTRL, SHIFT and/or ALT before the Drag&Drop operation begins. If you holds the keys CTRL+SHIFT pressed, a new sub class is derived. If you press the keys CTRL+ALT, a new instance of the class is created. The actual effect of the operation is additionally visualized in the mouse pointer. For more details please see the section Drag & Drop members.

In your concrete case, as far as I understood, you wanted to create an autoobject within a unit, right? In such case you Drag&Drop the class Core::Time by pressing the keys CTRL+ALT. See also Create new autoobject. The workaround to add the object to a GUI component and then to copy/paste it is not necessary.

I need access to Time.CurrentTime in the entire application.

Is this the reason for the usage of the autoobject? In other words, you plan to access CurrentTime via this global autoobject only? If yes, all the steps described above to create class variant are superfluous. In such case:

Step 1. Delete the class variant again.

Step 2: Instead, derive a new class from the Core::Time class. Name it, for example, Application::RTCTime.

Step 3: Within your new RTCTime class override the method getCurrentTime and adapt it accordingly.

Step 4: Create a new autoobject of the new RTCTime class.

Now the autoobject is an instance of the RTCTime class and as such it uses the modified getCurrentTime method.

Is this what you are trying to achieve?

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

...