Zitat von
generic:
Hinzukommt noch, wenn du dein Objekt erweiterst, kann es deine Routine nicht mehr laden.
Die Satzlänge passt dann nicht mehr.
Das Problem hat er aber mit deiner Methode auch.
@TE:
Die Zugriffsverletzungen kommen von der "komischen" Handhabung deines Datenpointers, würde ich mal behaupten.
So mach ichs:
1.) Statt String WideString
2.) Keine Dereferenzierung des Pointers beim holen der Daten
Delphi-Quellcode:
type
PTreeMenuEntry = ^TTreeMenuEntry;
TTreeMenuEntry = record
MainID : Integer;
ParentID : Integer;
UniqueID : Integer;
MenuTitle : WideString;
Flags : Integer;
ItemsCount : Integer;
ItemsSelected : Integer;
end;
// ...
procedure TDatabaseTree.DatabaseViewSaveNode(Sender: TBaseVirtualTree;
Node: PVirtualNode; Stream: TStream);
var
Data: PTreeMenuEntry;
c: Integer;
p: PWideChar;
begin
Data := DatabaseView.GetNodeData (Node);
Stream.Write (Data.MainID, SizeOf (Integer));
Stream.Write (Data.ParentID, SizeOf (Integer));
Stream.Write (Data.Flags, SizeOf (Integer));
Stream.Write (Data.ItemsCount, SizeOf (Integer));
Stream.Write (Data.ItemsSelected, SizeOf (Integer));
Stream.Write (Data.UniqueID, SizeOf (Integer));
c := Length (Data.MenuTitle) + 1;
Stream.Write (c, SizeOf (Integer));
p := PWideChar (Data.MenuTitle + #0);
Stream.Write (Data.MenuTitle[1], c * 2);
end;
procedure TDatabaseTree.DatabaseViewLoadNode(Sender: TBaseVirtualTree;
Node: PVirtualNode; Stream: TStream);
var
Data: PTreeMenuEntry;
c: Integer;
p: PWideChar;
begin
Data := DatabaseView.GetNodeData (Node);
Stream.Read (Data.MainID, SizeOf (Integer));
Stream.Read (Data.ParentID, SizeOf (Integer));
Stream.Read (Data.Flags, SizeOf (Integer));
Stream.Read (Data.ItemsCount, SizeOf (Integer));
Stream.Read (Data.ItemsSelected, SizeOf (Integer));
Stream.Read (Data.UniqueId, SizeOf (Integer));
Stream.Read (c, SizeOf (Integer));
c := c * 2;
GetMem (p, c);
Stream.Read (p^, c);
Data.MenuTitle := WideString (p);
FreeMem (p);
end;