Forum > Third party

Why dont add nodes in VirtualTree?

(1/1)

a5607593:
Hello,

help me, pls. I can't add nodes in vstOrders.

type
TMyRecord = record
Active: Boolean;
ID : Longint;
(здесь десяток полей)
NodePointer: PVirtualNode;
end;

rTreeData = record
IndexInMyData: integer;
end;

...

Procedure TForm1.LoadOrders;
var
Node: PVirtualNode;
Data: ^rTreeData;
i,Idx: integer;
Timer: cardinal;
begin
vstOrders.BeginUpdate;

Idx := length(MyArrayData);
SetLength(MyArrayData, length(MyArrayData)+frmDB.dbfOrders.RecordCount );

frmDB.dbfOrders.First;
repeat
Node := vstOrders.AddChild(nil);
Data := vstOrders.GetNodeData(Node);
Data.IndexInMyData := Idx; //а вот здесь возникает ошибка access violation. Node при этом содержит nil

with MyArrayData[Data.IndexInMyData] do begin
Active :=true;
ID :=frmDB.dbfOrders.FieldByName('ID' ).AsInteger;
(и здесь поля)
NodePointer:= Node; //Create link into your data record to VST node
end;
inc(Idx);
frmDB.dbfOrders.Next;
until frmDB.dbfOrders.EOF;
vstOrders.EndUpdate;

End;

Variable Node contains nil. I think, is not correct. May be i must initialize it, but where?

wp:
Did you somewhere define the size of the tree data record? Event OnGetNodeDataSize or property NodeDatasize.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- vstOrders.NodeDataSize := SizeOf(rTreeData);

taazz:

--- Quote from: a5607593 on August 05, 2018, 11:48:32 pm ---Hello,

help me, pls. I can't add nodes in vstOrders.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---typeTMyRecord = recordActive: Boolean;ID : Longint;(здесь десяток полей)NodePointer: PVirtualNode;end; rTreeData = recordIndexInMyData: integer;end; ... Procedure TForm1.LoadOrders;varNode: PVirtualNode;Data: ^rTreeData;i,Idx: integer;Timer: cardinal;beginvstOrders.BeginUpdate; Idx := length(MyArrayData);SetLength(MyArrayData, length(MyArrayData)+frmDB.dbfOrders.RecordCount ); frmDB.dbfOrders.First;repeatNode := vstOrders.AddChild(nil);Data := vstOrders.GetNodeData(Node);Data.IndexInMyData := Idx; //а вот здесь возникает ошибка access violation. Node при этом содержит nil with MyArrayData[Data.IndexInMyData] do beginActive :=true;ID :=frmDB.dbfOrders.FieldByName('ID' ).AsInteger;(и здесь поля)NodePointer:= Node; //Create link into your data record to VST nodeend;inc(Idx);frmDB.dbfOrders.Next;until frmDB.dbfOrders.EOF;vstOrders.EndUpdate; End; Variable Node contains nil. I think, is not correct. May be i must initialize it, but where?

--- End quote ---
virtual tree has a different model instead of pushing the data to the tree, it request the data. You only inform it on how many rows of data you have, ee you call rootnodecount = length(myArrayData); and use the events oninitnode and oninitchildren to set the nodes data and children respectively.

eny:

--- Quote from: taazz on August 06, 2018, 03:44:49 am ---virtual tree has a different model instead of pushing the data to the tree, it request the data. You only inform it on how many rows of data you have, ee you call rootnodecount = length(myArrayData); and use the events oninitnode and oninitchildren to set the nodes data and children respectively.

--- End quote ---
Although that is true, sequentially adding nodes should still work.
Hence wp's remark might be a nudge in the right direction.
A complete listing of the program will reveal the actual problem.

Navigation

[0] Message Index

Go to full version