EDIT: solved, is needed to add the getnodedatasize event:
procedure TfrmBuilder.VST1GetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(TTreeData);
end;
Without that the tree just doesn't load.
Thanks,
I am going to reopen this topic, with another problem that I am having, that is:
I can save and load flawlessly with two columns that contains strings:
type
PTreeData = ^TTreeData;
TTreeData = record
Fname: String;
quant: String;
End;
procedure TfrmBuilder.VST1LoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
data: PTreeData;
n: DWord;
begin
// Get pointer to the node's data
data := Sender.GetNodeData(Node);
// Read the string length (in characters)
n := Stream.ReadDWord;
if n > 0 then begin
// Set the length of the string
SetLength(data^.Fname, n);
if n > 0 then
// Read the string's characters
Stream.Read(data^.Fname[1], n * SizeOf(char));
end;
n := Stream.ReadDWord;
if n > 0 then begin
// Set the length of the second string
SetLength(data^.quant, n);
if n > 0 then
// Read the second string's characters
Stream.Read(data^.quant[1], n * SizeOf(char));
end;
end;
procedure TfrmBuilder.VST1SaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
data: PTreeData;
n: Integer;
begin
// Get pointer to the node's data
data := Sender.GetNodeData(Node);
// Write the length of the string (in characters)
n := Length(data^.Fname);
Stream.WriteDWord(n);
if n > 0 then
begin
// write the string characters
Stream.Write(data^.Fname[1], Length(data^.Fname) * SizeOf(char));
end;
// Write the length of the second string (in characters)
n := Length(data^.quant);
Stream.WriteDWord(n);
if n > 0 then
begin
// write the second string chars
Stream.Write(data^.quant[1], Length(data^.quant) * SizeOf(char));
end;
end;
BUT, when i try to save three columns, by just using the same method ( writing the string down in the stream), it loads at the first run of the executable, but when i close the exe, reopen and try to reload it gives an error, sisegv, in another words memory access violation
type
PTreeData = ^TTreeData;
TTreeData = record
Fname: String;
quant: String;
OBS: string;
End;
procedure TfrmBuilder.VST1LoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
data: PTreeData;
n: DWord;
begin
// Get pointer to the node's data
data := Sender.GetNodeData(Node);
// Read the string length (in characters)
n := Stream.ReadDWord;
if n > 0 then begin
// Set the length of the string
SetLength(data^.Fname, n);
if n > 0 then
// Read the string's characters
Stream.Read(data^.Fname[1], n * SizeOf(char));
end;
n := Stream.ReadDWord;
if n > 0 then begin
// Set the length of the second string
SetLength(data^.quant, n);
if n > 0 then
// Read the second string's characters
Stream.Read(data^.quant[1], n * SizeOf(char));
end;
{ THE CODE FOR THE THIRD STRING:
n := Stream.ReadDWord;
if n > 0 then begin
// Set the length of the THIRD string
SetLength(data^.OBS, n);
if n > 0 then
// Read the THIRD string's characters
Stream.Read(data^.OBS[1], n * SizeOf(char));
end;
}
end;
procedure TfrmBuilder.VST1SaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;
Stream: TStream);
var
data: PTreeData;
n: Integer;
begin
// Get pointer to the node's data
data := Sender.GetNodeData(Node);
// Write the length of the string (in characters)
n := Length(data^.Fname);
Stream.WriteDWord(n);
if n > 0 then
begin
// write the string characters
Stream.Write(data^.Fname[1], Length(data^.Fname) * SizeOf(char));
end;
// Write the length of the second string (in characters)
n := Length(data^.quant);
Stream.WriteDWord(n);
if n > 0 then
begin
// write the second string chars
Stream.Write(data^.quant[1], Length(data^.quant) * SizeOf(char));
end;
{
// Write the length of the THIRD string (in characters)
n := Length(data^.OBS);
Stream.WriteDWord(n);
if n > 0 then
begin
// write the THIRD string chars
Stream.Write(data^.OBS[1], Length(data^.OBS) * SizeOf(char));
end;
}
end;
What could it be? for 2 strings (2 columns) it works like a charm, but for three I got access violation?
Thanks in advance,
Leonardo
PS: a pic from the grid that i am trying to save / load
grid
As seen it has two columns, first is from data^.fname, second from data^.quant, and third should have been from data^.OBS, but it just doesn't load (sigsegv), so I took it out.