I wanted to primarily ask whether using TList would be more appropriate than changing the length of a dynamic array each time a new item is to be appended. Like so:
SetLength(DynamicArray, Length(DynamicArray)+1);
DynamicArray[length(DynamicArray)] := NewElement;
Assuming that it is more approrpiate.. I was wondering if something like this would work if I wanted to make a global dynamic array, accessible by all functions in the unit.
type
Tdata = Record
y: TList<real>;
x: TList<integer>;
End;
var
data: Tdata;
procedure TForm1.FormCreate(Sender: TObject);
begin
data.y := TList<real>.Create;
data.y.add(1.2);
data.y.add(2.3);
end;
procedure TForm1.ButtonClick(Sender: TObject); // Some button click event
begin
Memo1.lines.add(data.y.count); // Should output 2
end;
I'm confused as to where I need to create the TList, and why we need to create it in the first place, unlike a normal array. Do I need to create the TList again in the event function, and when would I free it? I am following this example, but i'm still confused how this would work with functions? Thanks, Jonathon
DynamicArray := DynamicArray + [NewElement]
– Brian