257 views
in GUI Development by
Hello,

Possibly I am missing something in my understanding of Chora data types:
Assume I have defined (as a brick derived from the GUI's Application:: class) a custom class holding multiple properties of simple data types (int32, string, bool). Now I instantiate, as a brick in the GUI, an array of that class.

Question 1:
Am I right to assume that this array won't receive any initialization values per default? This appears in contrast to simple properties that are, per default, initialized to 0. So I have to assign init values, otherwise I get an error message about accessing uninitialized array, right?

Question 2:
How do I assign initialization values to the individual array elements and the members contained therein? The "items" attribute of the brick appears to allow me to assign simple data values to simple data types, but not to arrayed members of custom classes, right?

Thanks,
Steffen

1 Answer

+1 vote
by

Hello Steffen,

Am I right to assume that this array won't receive any initialization values per default? This appears in contrast to simple properties that are, per default, initialized to 0. So I have to assign init values, otherwise I get an error message about accessing uninitialized array, right?

No. All data members are automatic pre-initilalized with zero values. This is an important safety aspect of Chora. 

How do I assign initialization values to the individual array elements and the members contained therein? The "items" attribute of the brick appears to allow me to assign simple data values to simple data types, but not to arrayed members of custom classes, right?

Let's assume you need an array of objects. Then you assign object instances to the array items. Depending on your application case, the objects will already exists or you create new instances of the objects. For example:

Now let's assume you want the Data objects to be initialized with some values just in the moment when the objects are assigned to array items. For this purpose you would need to create a method acting as initializer. The method parameters can be used to receive values which then are assigned to data members of the object. The number of method parameters and their data types depend on the data members you want to initialize. Finally the method returns the object itself. For example:

Now you can invoke the method just in-place where the object is created and assigned to an array item:

If this approach is not sufficient for your application case, you can initialize the array items in code of the Init method of the class containing the array. For example:

I hope, it answers your question.

Best regards

Paul Banach

by
Hi Paul,

Thanks for clarification.
I was looking for one solution and I actually got two to select from... Great!

I wasn't aware I could call a method from the Items attribute, this works just fine for me.

Thanks,
Steffen

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

...