411 views
in GUI Development by

Hi,

In our project we try to access array variable as like below 

1.created array variable inside a class(ex: arr_class)

2. passing that class as an argument to method in another class

3.inside method how can we access array variable which is there in (arr_class) class.

In above image array_class contain the array variable

  when we are trying to access the array facing issue like below




Thanks,

Harshini

1 Answer

0 votes
by

Hello Harshini,

similarly to C++, Chora is a static typed programming language. This means that before source code is compiled, the type associated with each and every single variable must be known. In your case the type of the variable obj is known as object. Such variable can represent any object. This however without any assumption to the content of the object. If you want to access a data member of such object, you have to explicitly type-cast it to the expected class and test whether the type-cast was successful (whether the object stored in the variable really does represent the desired class). See also Type conversion: Object runtime cast.

In your case (you plan to create an instance of a dynamically specified class), you could also use the Type conversion: Class runtime cast to distinguish the different classes. Once the class is known, you can perform code dedicated to the known class. For example:

// Trying to create an object of the Int32Array class?
if ((SomeUnit::Int32Array)array_class )
{
  var SomeUnit::Int32Array obj = new SomeUnit::Int32Array;

  trace obj.arr;
}

// Trying to create an object of the StringArray class?
else if ((SomeUnit::StringArray)array_class )
{
  var SomeUnit::StringArray obj = new SomeUnit::StringArray;

  trace obj.arr;
}

else if ( ... )
  ...

I hope it helps you further.

Paul Banach

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...