Recent

Author Topic: Why dont add nodes in VirtualTree?  (Read 1593 times)

a5607593

  • Newbie
  • Posts: 2
Why dont add nodes in VirtualTree?
« on: August 05, 2018, 11:48:32 pm »
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

  • Hero Member
  • *****
  • Posts: 6497
Re: Why dont add nodes in VirtualTree?
« Reply #1 on: August 06, 2018, 12:07:52 am »
Did you somewhere define the size of the tree data record? Event OnGetNodeDataSize or property NodeDatasize.

Code: Pascal  [Select]
  1.  vstOrders.NodeDataSize := SizeOf(rTreeData);
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: Why dont add nodes in VirtualTree?
« Reply #2 on: August 06, 2018, 03:44:49 am »
Hello,

help me, pls. I can't add nodes in vstOrders.
Code: Pascal  [Select]
  1. type
  2. TMyRecord = record
  3. Active: Boolean;
  4. ID : Longint;
  5. (здесь десяток полей)
  6. NodePointer: PVirtualNode;
  7. end;
  8.  
  9. rTreeData = record
  10. IndexInMyData: integer;
  11. end;
  12.  
  13. ...
  14.  
  15. Procedure TForm1.LoadOrders;
  16. var
  17. Node: PVirtualNode;
  18. Data: ^rTreeData;
  19. i,Idx: integer;
  20. Timer: cardinal;
  21. begin
  22. vstOrders.BeginUpdate;
  23.  
  24. Idx := length(MyArrayData);
  25. SetLength(MyArrayData, length(MyArrayData)+frmDB.dbfOrders.RecordCount );
  26.  
  27. frmDB.dbfOrders.First;
  28. repeat
  29. Node := vstOrders.AddChild(nil);
  30. Data := vstOrders.GetNodeData(Node);
  31. Data.IndexInMyData := Idx; //а вот здесь возникает ошибка access violation. Node при этом содержит nil
  32.  
  33. with MyArrayData[Data.IndexInMyData] do begin
  34. Active :=true;
  35. ID :=frmDB.dbfOrders.FieldByName('ID' ).AsInteger;
  36. (и здесь поля)
  37. NodePointer:= Node; //Create link into your data record to VST node
  38. end;
  39. inc(Idx);
  40. frmDB.dbfOrders.Next;
  41. until frmDB.dbfOrders.EOF;
  42. vstOrders.EndUpdate;
  43.  
  44. End;
  45.  
Variable Node contains nil. I think, is not correct. May be i must initialize it, but where?
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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

eny

  • Hero Member
  • *****
  • Posts: 1588
Re: Why dont add nodes in VirtualTree?
« Reply #3 on: August 06, 2018, 04:49:59 pm »
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.
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.
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...