How to save a treeview with all nodes and their record object attached? When load from a blob field in table then when i click on node then show info stored in node.data.
I have this :
type
PMyRec = ^TMyRec;
TMyRec = record
text:string;
codigo:string;
medida:string;
parent:string;
ativo:String;
Tipo: string;
wasExpanded:boolean;
end;
var
Form1: TForm1;
MyRecPtr: PMyRec;
when i add a node:
New(MyRecPtr);
MyRecPtr^.Tipo := 'R';
MyRecPtr^.codigo := edit1.text;
MyRecPtr^.parent := edit3.text;
MyRecPtr^.text := edit2.Text;
Tree1.Items.AddChildObject(nil,ansiuppercase(edit1.text+' '+edit2.text),MyRecPtr);
when user clic in a item of the tree:
Node:=tree1.Selected;
if PMyRec(Node.Data)^.Tipo='R' then
begin
edit1.Text:=PMyRec(Node.Data)^.codigo;
edit2.Text:=PMyRec(Node.Data)^.text;
edit3.Text:=PMyRec(Node.Data)^.parent;
end;
i have a tree with more than 4000 items! read from a stored from a file item by item and then create a record point for each one is extremely slow! But when save as Tmemorystream blob and them load is so fast but record object are not saved.
Is is possible idea or give example how to save a tree and all record object attached so when load from a file when clicked in a node then show info from their record object attached?
Thansk
I read a lot of things on internet but no works
i found this: text
When saved object conver into a integer "writer.WriteInteger(Integer(node.data))" and then when load convert into a pointer "node.Data := Pointer(Reader.ReadInteger)" , but when click in item of tree rise arror! i think there is no memory allocation.
You write address of data, that has no sense in another process. If all node data contains the same record type, you have to change (I didn't checked overall correctness of the tree save-restore):
writer.WriteInteger(Integer(node.data));
...to the sequence:
writer.WriteString(PMyRec(Node.Data)^.text);
...
writer.WriteString(PMyRec(Node.Data)^.Tipo);
writer.WriteBoolean(PMyRec(Node.Data)^.wasExpanded);
And similarly instead of:
node.Data := Pointer(Reader.ReadInteger);
...use:
New(MyRecPtr);
MyRecPtr^.text := Reader.ReadString;
...etc. and finally:
node.Data := MyRecPtr;