0

Could someone please show me a good example of VirtualStringTree.CopyTo? I have made an application that adds, deletes nodes, but I can not make the CopyTo work correctly. My goal is to use the CopyTo function to copy a node and its children to another location. The CopyTo function seems to use the savenode and loadnode functions...

clarification: i looked at my LoadNode and SaveNode methods;

for the following type TTreedata, I have made the following load and save methods:

type
   PTreeData = ^TTreeData;
   TTreeData = record
      FCaption: String;
      FRichText: String;
      FImageIndex: integer;
      FVisibility: integer;
      FUniqueID: integer;
   end;


procedure vstSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
var
   Data: PTreeData;
   Len: integer;
begin
   Data:=Sender.GetNodeData(Node);

   //FCaption
   Len:=Length(Data.FCaption);
   Stream.Write(Len, SizeOf(Len));
   Stream.Write(PChar(Data.FCaption)^, Len * SizeOf(Char));

   //FRichText
   Len:=Length(Data.FRichText);
   Stream.Write(Len, SizeOf(Len));
   Stream.Write(PChar(Data.FRichText)^, Len * SizeOf(Char));

   //FImageIndex
   Stream.Write(Data.FImageIndex, SizeOf(Data.FImageIndex));

   //FVisibility
   Stream.Write(Data.FVisibility, SizeOf(Data.FVisibility));

   //FUniqueID
   Stream.Write(Data.FUniqueID, SizeOf(Data.FUniqueID));

end;

procedure vstLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
var
   Data: PTreeData;
   Len: Integer;
begin
   Data := Sender.GetNodeData(Node);
   //Len:=Length(Data.FCaption);

   //FCaption
   Stream.Read(Len, SizeOf(Len));
   SetLength(Data.FCaption, Len);
   Stream.Read(PChar(Data.FCaption)^, Len * SizeOf(Char) );

   //FRichText
   Stream.Read(Len, SizeOf(Len));
   SetLength(Data.FRichText, Len);
   Stream.Read(PChar(Data.FRichText)^, Len * SizeOf(Char));

   //FImageIndex
   Stream.Read(PChar(Data.FImageIndex)^, SizeOf(Data.FImageIndex));

   //FVisibility
   Stream.Read(PChar(Data.FVisibility)^, SizeOf(Data.FVisibility));

   //FUniqueID
   Stream.Read(PChar(Data.FUniqueID)^, SizeOf(Data.FUniqueID));
end;

When I use Copy function on a selected node, when I step into the function LoadNode in the Debug mode, it gives me an access violoation (Delphi XE8) write of address 000000000000000 at the line

  Stream.Read(PChar(Data.FImageIndex)^, SizeOf(Data.FImageIndex));

Thanks

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

0 Answers0