Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PASCAL : Get Length of array[x]

How can I get the Length of an array with a specific index for example if I have an array like this

TYPE T_PERSON = PACKED RECORD
  Example : STRING[40];
  Example2 : STRING[10];
  Example3 : STRING[5];
END; 
example: ARRAY [1..30] OF T_PERSON 

and I want to know the Length of example[28] respectively example[x]. Can I get it with LENGTH() or is there another solution?

like image 485
Mahmoud Avatar asked Oct 17 '25 18:10

Mahmoud


1 Answers

If it is an array and you want the number of elements:

 high(example)-low(example)+1;

Afaik with Free Pascal and Delphi 4+ length might also work, but don't pin me on that.

If you need the size in bytes, Abelisto is correct and sizeof() is what you want, and it also works on parts of the record (e.g. sizeof(example.example)).

The sum might not add up though if you are not PACKED due to alignment bytes.

like image 146
Marco van de Voort Avatar answered Oct 19 '25 12:10

Marco van de Voort



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!