有人可以告诉我一个VirtualStringTree.CopyTo的好例子吗?我已经创建了一个添加,删除节点的应用程序,但我无法使CopyTo正常工作。我的目标是使用CopyTo函数将节点及其子节点复制到另一个位置。 CopyTo函数似乎使用了savenode和loadnode函数......
澄清: 我查看了我的LoadNode和SaveNode方法;
对于以下类型的TTreedata,我做了以下加载和保存方法:
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;
当我在所选节点上使用复制功能时,当我在调试模式下进入函数LoadNode时,它会给我一个访问violoation(Delphi XE8)写入地址000000000000000的行
Stream.Read(PChar(Data.FImageIndex)^, SizeOf(Data.FImageIndex));
由于