1.3k views
in Embedded Wizard Studio by
Hallo everybody,

i am new in Embedded Wizard. So i tried to start with my application. I made different classes, which everyone has is one functions and handlers. Now i want to know how can i call a function von Class B when i am in Class A.
Example:
Class B has a simple touch handler, with a function which enables or disables the touch handler. In Class A i want to enter this function from Class B to control the touch handler. How is this possible?

2 Answers

0 votes
by
 
Best answer

Hi,

similarly to other object-oriented programming languages, the methods (functions) of a class are invoked in context of an object (instance) of the affected class. In your particular case, you will need to invoke the desired method in contect of an object created from class B. Please see: Use the method if you intend to invoke a regular method, or see Use the method if you want a slot method being invoked. 

The object, in context of which you want to invoke the methods can be either embedded within the actual class or you create dynamically a new instance of the object and use it to invoke the method. Alternatively, you can manage within your project so-called autoobjects, which can be seen as global instances of a particular class you can access from everywhere in yopur project.

In order to give you a more exact answer I would need to understand the relation between class A and B in your project. I assume, A and B are two GUI components. Does A contain an embedded instance of B? Or are the instances of A and B two siblings embedded within another component? Anyway, I hope the answer above will help you to clarify the aspect.

Best regards

Paul Banach

by
Hallo Paul,

thank you for your fast reply. I wrote all the documentation and it was very helpful. I can call the methods or slot methods. But it doesent solved my problem. For better understanding here more details:

I have an GUI Component (Class A) with a Vertical List. This Vertical List is filled with another GUI Component (Class B). The Component in Class B has an Simple Touch Handler, which i want to enable or disable in the Class A.

So now i made an method in class B called enableTouch with the following Code:

if( SimpleTouchHandlerClassB.Enabled )
{
  SimpleTouchHandlerClassB.Enabled = false;
}
else
{
  SimpleTouchHandlerClassB.Enabled = true;
}
the initial State of the Touch Handler in Class B is disable.

In Class A i have a Button, if this Button is pressed i call the  function onPressed with the following code:

var Application::ClassB itemObject;
itemObject =  new Application::ClassB;
itemObject.enableTouch();

the function enableTouch is entered but the TouchHandler it self is not enabled or disabled.
by

In your actual implementation you create a new instance of ClassB and call the enableTouch() method on it. Since the method enableTouch() is called in context of the just created new instance, it affects exact this instance only. The other instances existing in the vertical list are not affected by this operation. Every instance is stored and treated individually.

To achive the desired function you would need to call enableTouch() in context of the affected instance existing in the vertical list. You can do following:

1. First obtain the desired ClassB instance existing in the vertical list by using the method GetViewForItem().

2. Once you know the instance, you can invoke the method enableTouch() on it. However, since GetViewForItem() returns the instance interpreted as a generic view, an additional object runtime cast is necessary before you can call enableTouch().

The following source code demonstrates how you call the method for the first item in the vertical list:

// Ask the vertical list for the view corresponding to the first item
var Core::View view = VerticalList.GetViewForItem(0);

// Apply the object runtime cast to ensure that the returned view
// is really the 'ClassB' instance
var YourUnit::ClassB viewClassB = (YourUnit::ClassB)view;

// Successful? Then invoke the method.
if ( viewClassB != null )
  viewClassB.enableTouch();

With this approach you access the views individually by specifying the corresponding vertical list item number. 

Using this approach you should keep in mind, that the vertical list is optimized to manage the item views very efficiently. This means in practice, the list limits to store the views for the actually visible items only. When you scroll the list, the views are released or reused to display other items.

Thus the above described approach will fail as soon as you scroll the list or you try to access the view for an actually invisible item. This is therefore not the optimal approach unless you know what you do. Anyway, the above description should help you to understand the intern aspects of vertical list, its items and the corresponding views.

From my point of view I would prefer one of the following two aproaches. Which is applicable depends on your aplication case and what you want to achieve:

Approach 1: Do you want the touch handlers to be disabled for ALL items in the vertical list? In this case you don't need to access the items individually and call enableTouch() on them. Instead simply set the property Enabled of the vertical list to the value false. This disables the vertical list from being able to handle and dispatch touch and keyboard events. Accordingly the views embedded in the vertical list are also disabled.

Approach 2: You want the touch handler being disabled individually. Here I would store for every vertical list item its actual enabled state and use it in the OnLoadIItem method to enable/disable the item. As you know, the vertical list itself doesn't store the complete set of all item data. It manages only the few actually visible items. When the user scrolls the list, the list signals the OnLoadItem method asking your implementation for the content of the just exposed item. Thus your implementation of OnLoadItem method has to access some storage where the complete list information is managed. In the simplest case this can be an array. More sophisticated applications use data bases.

The idea of this approach 2 is thus to enhance the information the array/data base store for every item by the additional enabled/disabled state. Then in the OnLoadItem method you accordingly enable or disable the touch handler.

Now in the ClassA you don't access the vertical list items anymore. When you want the enabled state of one of the items being toggled, you toggle ONLY the corresponding state information in the array or data base. Then you Force the list to reload the affected item again. By reloading the item, the OnLoadItem method is called causing the affected list item being updated to its new state you have previously updated in the array or data base.

With this approach you don't need to worry about the items when the user scrolls the list and every item can manage its enabled/disabled state individually.

Hope it helps you further.

Best regards

Paul Banach

0 votes
by

thank you very much for the detailed reply. It was very helpful and i could fix my problem even made it more efficient.
I used your Approach 1.  But for the understanding of an Vertical or Horizontal List it was also helpful.

best regards
Torben

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

...