Android Question sizeof(x) equivalent b4a

MbedAndroid

Active Member
Licensed User
already searched forum, but how to determin a size of array or type in B4a?
For random acess i need to forward the point to a offset i*sizeof(y) where i is the pointer to the stored location and y and var which holds the type of vars
 

MbedAndroid

Active Member
Licensed User
doesnt work
i need to know the sizeof spots
B4X:
Type SPOTSLABELS  (spotname As String,  positie As Position, Date As String, Time As String)
Dim Spots As SPOTSLABELS
/[code]
spots.length doesnt work
 

MbedAndroid

Active Member
Licensed User
it works for 1 var inside the type
i could make a adding of all the var's inside the type, that should work, but there must be a much easier way, only i dont know the equivalent in basic or b4a basic
Normally in #c you say sizeof(array) etc
 

stevel05

Expert
Licensed User
A Type is actually a class, the variables it holds are available by reference.

If you explain what you are trying to achieve it may be possible to get the result in different ways.
 

MbedAndroid

Active Member
Licensed User
A Type is actually a class, the variables it holds are available by reference.

If you explain what you are trying to achieve it may be possible to get the result in different ways.
i'm saving several files, random each of type "spots" To index the pointer i need to know the size of "spots". I found this manually (304 bytes) so the application is working

the best way is to count each var inside the type like Erel mentioned in his answer. Basic doesnt seem to have a equivalent command of sizeof in C#
 

stevel05

Expert
Licensed User
If the Type holds non string variables then the length would be dependent on the value of the variable value, if the values are numeric, you could cast them to a string and measure their length but if they are boolean or another class or type then it would be more complicated.
 
Last edited:

MbedAndroid

Active Member
Licensed User
one way is to set the length much larger then the actual size of type. Then the file contains blocks where the type will fit. This works, but not a nice way...
 

Yalçın Kondur

Member
Licensed User
I'm not sure if an equvalent of Delphi's SizeOf(TRecord) command exists in B4A.

Edit: Where did Delphi come to my mind?
 
Last edited:

MbedAndroid

Active Member
Licensed User
You can use a list instead of a customtype. You then can get the lists length.
Size AsInt [read only]

Returns the number of items in the list.
size only returns the number of items, not the total size in bytes
I'm not sure if an equvalent of Delphi's SizeOf(TRecord) command exists in B4A.

Edit: Where did Delphi come to my mind?
if Erel should release a C#4a i would buy it right away....
 
Top