205 views
in GUI Development by
Hi,

I've created one class, say Application::ScreenSwitchClas.
Inside of this ScreenSwitchClass I've added the following members as follows
1. screen_name property of type Core::Group
2. key_code property of type int32 ( It'll be updated from Application::DeviceClass)
3. screen_switch method
    screen_switch(screen_name, key_code)
    {
          screen_name = ScreenSwitchClass.screen_name;
          key_code = ScreenSwitchClass.key_code;
          if(key_code == 5)
          SwitchToDialog( screen_name, null, null, null, null, null, null, null, null, null, false );
     }
4. So now I'm adding this ScreenSwitchClass as an object inside of one component class ScreenA, and I'm giving values for the properties I've added by affecting this ScreenSwitchClass object and in the inspector window I'm giving the values.
5. screen_name = Application::ScreenB, key_code = 5
6. While running the prototype I'm getting errors like
    SwitchToDialog Call to an unknown method(This is due to I've not inherited the ScreenSwitchClass as SuperClass of Core::Group)
    So that I've created one variable fake_owner of type Core::Group inside of ScreenSwitchClass and used that variable inside of screen_switch method as follows
    fake_owner.SwitchToDialog( screen_name, null, null, null, null, null, null, null, null, null, false );
7. Now while running the prototyper it shows that the fake_owner is in null object.
8. I need help to implement the Owner relationship from component class to a normal class without inheriting the SuperClass property with Core::Group, So that I can able to add this ScreenSwitchClass object inside of all Application classes just to configure the key_code and screen_name.
9. How to make this ScreenSwitchClass as a generic object so as to configure the screen_name and key_code as given as inputs, so it'll the process the screen switch from one screen to another screen
10. If this kind of approach is possible, then no need of writing more slot methods inside of Application classes, so that user can just add as many as ScreenSwitchClass object for various key_code and various screen_name within the same Application::ScreenClass

Kindly suggest some ideas

Thanks & Regards

Dinesh Thirumaran

1 Answer

0 votes
by

Hello Dinesh,

when working with the dialog methods (e.g. SwitchToDialog()) it is important to take in account that the methods have to be invoked in context of an existing GUI component. The dialog will thereupon appear within this component. The trick with fake_owner will not work therefore. What can you do? Here are a few ideas and tips:

Idea 1: You can access from an object the superior component the object is embedded inside. For this purpose use the variable parentthis. For example, in your method screen_switch you could try following:

var Core::Group parent = (Core::Group)parentthis;

if ( parent )
  parent.SwitchToDialog( ... );

Idea 2: As mentioned at the beginning of my answer (and described in Take a closer look at the Dialog functionality), the invocation of SwitchToDialog() will present the dialog within the GUI component in context of which the method has been invoked. Therefore, when each invocation of SwitchToDialog() is perform in context of a different component (different screen), you will in fact nest all dialogs inside different components creating each time more complex screen tree.

It is thus essential to perform the SwitchToDialog() operations always in context of one and the same owner component (unless your application case requires multiple dialogs to exist simultaneously). In the simplest case, you could present the dialogs always in context of the Application component. For this purpose, you need to access the Application component (the so-called root object) from your implementation. You do this as shown below by invoking the method GetRoot():

var Core::Group parent = (Core::Group)parentthis;
var Core::Root  root   = parent? parent.GetRoot() : null;

if ( root )
  root.SwitchToDialog( ... );

If you are working with Embedded Wizard 12 or newer, you can use the variable rootthis to access the root object directly. This would reduce your implementation of the method to a single line of code:

rootthis.SwitchToDialog( ... );

Idea 3: If all you want is to to switch top-level dialogs and you don't plan to perform any animations during the dialog transitions, you can use the properties ActiveDialog and ActiveDialogClass available in the Application component. This would even once more simplify the implementation:

rootthis.ActiveDialogClass = your_class;

... or if you are working with version <= 11:

var Core::Group parent = (Core::Group)parentthis;
var Core::Root  root   = parent? parent.GetRoot() : null;

if ( root )
  root.ActiveDialogClass = your_class;

I hope it helps you further ...

Best regards

Paul

by
Hi Paul,
Thanks for your ideas

Further I've implemented the Idea 1. It's working for my requirements.

So for this, inside of ScreenSwitchClass I want to give the dialog group as a property named screen_name. So that I can able to give the dialog class as a argument to make it configurable and generic.

 parent.SwitchToDialog( aDialogGroup, null, null, null, null, null, null, null, null, null, false );

1. So here aDialogGroup is a argument of type Core::Group ,
2. To give the screen name as argument for aDialogGroup which type I should need to take for the property screen_name. Or How to typecast it.
3. Also how to use the new operator for this purpose to keep inside of SwitchToDialog() method.
by

Hello Dinesh,

2. To give the screen name as argument for aDialogGroup which type I should need to take for the property screen_name. Or How to typecast it.

It depends on what you plan to assign to the screen_name property. If it is already an object, then declare screen_name with Core::Group. This will ensure that only instances of Core::Group are permitted here. No other typecast is needed. The object stored in screen_name can be passed directly to the SwitchToDialog() method. This approach requires thus that you create the object in advance before assigning it to the screen_name property. For example by using the new operator.

If you want to assign to the property a class implementing some dialog to present, then screen_name has to be declared with the type class. This last approach requires that you additionally creates an instance of the class before invoking the SwitchToDialog() method. For example:

var Core::Group dialog = (Core::Group)new screen_name;

if ( dialog )
  [????].PresentDialog( dialog, ... );

In fact the both approaches are exact what the properties ActiveDialog and ActiveDialogClass do as explained in the idea 3. Note the additional typecast which is obligatory in the last approach since the resulting type of the object created by a new operator with class as operand is unknown at the compilation time. The Chora compiler assumes the result as the most generic object type.

3. Also how to use the new operator for this purpose to keep inside of SwitchToDialog() method.

Not sure what you mean with "... inside of SwitchToDialog().". I hope the second approach above demonstrates the usage of the operator. See also Operators: new.

Best regards

Paul

 

 

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

...