Add Obj then Remove Obj

30 views
asked Feb 20 in Embedded Wizard Studio by Andy

Hi, 

As title

I press button A to Add object

var Menu::Menu_GPS_Map menu = new Menu::Menu_GPS_Map;
GetRoot().Add(menu,0);

and I press button B to Remove object

var Menu::Menu_GPS_Map view = (Menu::Menu_GPS_Map)GetRoot().GetModalGroup();
GetRoot().Remove(view);

it didn't work and it said view is null

I think the below line is wrong but I don't know how to modify it.

var Menu::Menu_GPS_Map view = (Menu::Menu_GPS_Map)GetRoot().GetModalGroup();

Is there any suggestions ?

Thanks!

 

Best Regards,

Andy

1 Answer

0 votes
answered Feb 20 by Paul Banach
 
Best answer

Hello Andy,

from your code I suppose the problem is related to missing BeginModal() invocation. The invocation Add() limits to add the affected component to root object. This component, however, is not modal. To make it modal you need to invoke BeginModal() too. Without this, there is no modal GUI component and the invocation GetModalGroup() returns null.

Try following:

var Menu::Menu_GPS_Map menu = new Menu::Menu_GPS_Map;
GetRoot().Add(menu,0);
GetRoot().BeginModal( menu );

[...]

var Menu::Menu_GPS_Map view = (Menu::Menu_GPS_Map)GetRoot().GetModalGroup();
GetRoot().Remove(view);
GetRoot().EndModal( view );

Does it help you?

Best regards

Paul Banach

commented Feb 21 by Andy

Hi,

It works but it's a little different in my condition.

In my condition,

I can use cursor key to select picture A,B,C,D

I press picture A and it will add Object A on View.

Then, if I press picture C and it will remove Object A and add Object C on view.

Since using BeginModal() will focus on the new object, then I can't use cursor to select other picture.

Is there any way to implement it ?

Thanks

 

Best Regards,

Andy

commented Feb 21 by Paul Banach

Hello Andy,

if the modal state is not desired, I see three possibilities:

Option 1: In your component add a new variable. Configure the data type of the variable to Core::Group which is common for all GUI components. Then when you create new view emember it in the variable. Later when you switch to another view, just use the variable to Remove() the old view and create the new one. For example:

var Menu::Menu_GPS_Map menu = new Menu::Menu_GPS_Map;
GetRoot().Add(menu,0);

// The new variable to store the current view.
CurrentView = menu;

[...]

GetRoot().Remove( CurrentView );
CurrentView = null;

Option 2: Within your GUI component where you show the views, you can enumerate/search for existing views. In this way you can find the view shown actually and remove it before you show another one. See the section Enumerate and search views existing within the component.

Option 3: Manage the views as dialogs. For this purpose you use the method SwitchToDialog(). The underlying functionality remembers which dialog is actually visible so switchting to another dialog will hide the old one. Please see the section Managing Dialogs.

Concerning the options 1 and 2 I would also recommend to study the section Communication between components-

Does it help you further?

Best regards

Paul Banach

commented Feb 24 by Andy
Hi, Paul

I think Option 1 is a good method to implement my need.

Thanks for your help!!

Best Regards,

Andy Dong

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

...