I was wondering if it is possible to declare an empty global array? I find when you declare an array you dimension it and therefore create the elements, but I would like to create an empty array and then dimension it at some later point at runtime. I suspect I can't do what I am thinking and the List is really the solution, but I thought I would ask none the less?
Here is an example of what I have tried but the compiler does not like. My first thought was to maybe dim the array using -1 to give a size of 0, but the compiler does not like it.
devox wrote: ↑Mon May 29, 2023 3:57 pm
I was wondering if it is possible to declare an empty global array? I find when you declare an array you dimension it and therefore create the elements, but I would like to create an empty array and then dimension it at some later point at runtime. I suspect I can't do what I am thinking and the List is really the solution, but I thought I would ask none the less?
Hi,
Help Dim / Redim Dim is used to create new arrays ReDim is used to 'resize' an already declared array while preserving its content.
Has one element dimensioned. The ArraySize() is a little misleadingly named as it actually returns the ubound of the array so therefore it's size is 1 and is not empty.
I was wondering if it is possible to create a declaration for it that is an array of zero elements? I have a feeling list is the real solution as from what I am reading you can only dim 1 or more elements.
Structure myArray
Array item.s(0)
EndStructure
Global *my.myArray = AllocateMemory(SizeOf(myArray) )
; (1) *my pointer points to an integer-sized buffer
InitializeStructure(*my, myArray)
; (2) create a one-cell-sized array (indexed with #0)
*my\item(0) = "12345"
Redim *my\item(7)
; (3) resize the array as an 8-cells-sized array
Debug *my\item(0)
; (4) redim function has not zeroed the initial value
Redim *my\item(0)
; (5) reduce the array to a single-cell size
ClearStructure(*my, myArray)
; (6) DESTROYS THE WHOLE ARRAY
; Debug *my\item(0)
; (7) triggers an error if uncommented
InitializeStructure(*my, myArray)
; (8) rebuild an array
Debug *my\item(0)
; (9) Displays 0 (but not the previewing '12345' value)
Thanks that is even better! Thank you very much. I wish you could init it with array size 0, rather than init with one element then clear, but it is a minor annoyance.