type
// ............
TArrPayload = array of PPayload; // As I told, set this to array of pointers, not records
// .......
var
Form1: TForm1;
ArrPayload: TArrPayload;
implementation
procedure TForm1.FormCreate(Sender: TObject);
const
NumItems = 5;
var
i: integer;
rec: PPayload;
begin
// populate a dynamic array
// ArrPayload := TArrPayload.Create;
SetLength(ArrPayLoad, NumItems); // I fixed length, but your approach would be nicer if the size is not known.
for i := 0 to High(ArrPayLoad) do
begin
New(rec); // You need to allocate memory to rec with New
rec^.ID := i;
rec^.Name := Format('Node %d', [i]);
ArrPayLoad[i] := rec; // rec, which is pointer is stored in the array.
end;
// initalize the nodes - want the adress of the records as payloads
VirtualStringTree1.NodeDataSize := SizeOf(PPayload);
{ // I commented out these
// these work ...,
for i := low(ArrPayload) to high(ArrPayload) do
begin
VirtualStringTree1.AddChild(nil,@ArrPayload[i]);
end;
// }
// following seems to work
for rec in ArrPayload do
VirtualStringTree1.AddChild(nil, rec);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
rec: PPayLoad;
begin
for rec in ArrPayLoad do Dispose(rec); // You have to free memory, as these are using heap memory, not stack.
end;