Your product seems to be very nice but I have a question.
I can set the Text property of a node, but I need save a file name with the node also. This file name should not be visible but must be save in the *.mt file.
Do you understand what I search to do ?
How can I do ?
Regards.
But can I save an ID ?
regards
> But can I save an ID ?
>
> regards
Dear Bournisien,
MetaTree Component developer is out of town. He will reply you as soon as possible.
Best regards,
| Lena Klimova
| Customer Service Representative
Lena.Klimova@metaproducts.com
I send an email.
Regards.
> > An other thing: If I can save an ID for each node it is perfect because I can use an other database for the other datas.
> > But can I save an ID ?
> >
> > regards
>
> Dear Bournisien,
> MetaTree Component developer is out of town. He will reply you as soon as possible.
>
> Best regards,
>
> | Lena Klimova
> | Customer Service Representative
> Lena.Klimova@metaproducts.com
> But can I save an ID ?
>
> regards
I am sorry for the long delay.
The object TMTNode do not has ID property.
Therefore you can not save it.
But you can save MetaTree to a database anyway.
This is an example on how to do it.
===
procedure TForm1.ConstructTree;
var
Root: TMTNode;
// The tree structure stored in the table named "tree".
// This table consists of the following fields:
// [ID] [int] - unique record identifier.
// [ParentID] [int] - identifier of the parent node
// [Name] [char] (30) - Caption of the tree node
// [Icon] [smallint] - Icon index of the tree node
//
procedure FillTree(Const N: TMTNode; Const ParentID: Integer);
var
s: String;
i: Integer;
N1: TMTNode;
Temp: TList; // Stores list of all children of node N;
begin
with Query1 do
begin
SQL.Text :=
Format(`SELECT * FROM tree WHERE ParentID=%d`, [ParentID]);
Open;
Temp := TList.Create;
while not Eof do
begin
S := Trim(FieldByName(`Name`).AsString);
if s <> `` then
begin
N1 := MetaTree1.Items.Add(N, s);
with N1 do
begin
Data := Pointer(FieldByName(`ID`).AsInteger); // Save user-defined data
ImageIndex := FieldByName(`Icon`).AsInteger;
end;
Temp.Add(N1);
end;
Next;
end;
Close;
for i := 0 to Temp.Count - 1 do
FillTree(Temp[i], Integer(TMTNode(Temp[i]).Data));
Temp.Free;
end;
end;
begin
MetaTree1.BeginUpdate; // don`t repaint the Metatree
MetaTree1.Items.Clear;
// I added the root node manually, not from database
Root := MetaTree1.Items.Add(nil, `MetaTree`);
FillTree(Root, 0);
MetaTree1.EndUpdate; // It`s OK. Now we will repaint the MetaTree
end;
===
Sincerely,
Alex Filatkin
MetaProducts corp.
> Your product seems to be very nice but I have a question.
> I can set the Text property of a node, but I need save a file name with the node also. This file name should not be visible but must be save in the *.mt file.
> Do you understand what I search to do ?
> How can I do ?
>
> Regards.
I am sorry for the long delay.
First, the object TMTNode has such property:
property Data: Pointer;
You can use this property to associate any user-defined data with a node.
Second, MetaTree does not have built-in capabilities to save user-defined data in *.mt files.
If you want to use the standard MetaTree methods to work with the *.mt file,
try to use the next trick:
1)Before saving
Call method MetaTree.BeginUpdate; // do not repaint the MetaTree
Now for each node please do the following
Node.Text := Node.Text + `#` + strFileName;
Where `#` is a delimiter for the node caption and your data
Call MetaTree.SaveToFile(FileName);
Restore Node.Text for each node (Or call your modified Load method (please, see below)).
Call MetaTree.EndUpdate;
2) After Loading
Call MetaTree.BeginUpdate;
Call MetaTree.LoadFromFile(FileName);
Then for each node please change the Node.Text property to split node caption and your data.
Save your data in the Data: Pointer property.
Call MetaTree.EndUpdate;
Sincerely,
Alex Filatkin
MetaProducts corp.