Question about structures

derez

Expert
Licensed User
Longtime User
B4X:
Note that it is still not possible to pass or return arrays and structures

It is possible for a method in a library to refer to an array as an argument in the method, and it is actually by reference.

Since structure is an array, it can also be referenced in the method.

The method has strong typing, hence the type of the array must be the same as in the program.

If I want to use a structure which contains various types (say number and string) - it is not accepted by the method and on the other hand it can't be declared in the b4ppc other than leave it as default string.

I tried to declare the items of the structure inside the type declaration but it does not accept it.

I still want to use part of the structure and copy from it within the method, how can I refer to this mixed structure in c# ?

the work around is of course to create in the program another partial structure with only the necessary parts, but this is loading the program.

thanks for any clarifying answer.

Edit: I forgot the other way - to leave it as string and to convert it in the method. I'll try that, but would like to understand more anyway.
Edit: the last idea works.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Because a "structure" in Basic4ppc is not really a structure but an array it can only hold items of a single type - unlike a .NET structure. A Basic4ppc "structure" is really only an indexing convenience.

To pass a Basic4ppc "structure" to a library you need to define a method parameter or property as an array of the correct type and rank. You can return an array of the correct type and rank to Basic4ppc as a method return or property. C# structs cannot be passed to or from a library as Basic4ppc only knows about arrays and variables.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…