Page 1 of 1
problems trying to save TDBTree and reopen with teeTreeOffic
Posted: Thu Jun 08, 2006 2:31 pm
by 7723130
hi
i am modifying tDBTree objects using a script.
but i would really need to reopen them using teeTreeOffice
here is my code
TDBTree : arbre;
racine : TTreeNodeShape;
filsCodeOM : TTreeNodeShape;
...
LoadTreeFromFile(TCustomTree(arbre), lst
);
arbre.NoOwnerShapes := false;
arbre.AssignParent := false;
if (arbre.Roots.Count > 0) then racine := arbre.Roots[0];
filsCodeOM := racine.AddChild(TXT_CODE_OM);
filsCodeOm.AddChild(intToStr(_codeOm));
filsCodeOm.Font.style := [fsBold];
ForceDirectories('E:\mCaron\apresScript' + nouveauPath);
SaveTreeToFil(arbre, 'E:\mCaron\apresScript'+nouveauPath+nomFichier);
...
the error message i get when i reopen the code modified tree is
error reading treeNodeShape2.text.string : invalid property value
and all i see is some sort of empty gray panel
i would really appreciate you help
gracias
mathieu caron
[email protected]
Posted: Thu Jun 08, 2006 3:26 pm
by Tom
Hi mCaron,
I'm not sure I can follow your code. You use a dbTree, but load a file into it to create a tree? Or how do you create the tree? Why do you need to use LoadTreeFromFile?
What is TXT_CODE_OM ?
Thanks,
tom
Posted: Thu Jun 08, 2006 3:35 pm
by 7723130
hi tom
firstly, a employee at our company create the teeTrees using teeTreeOffice.
I was asked to add an other information in all our teeTrees (a unique id number). we have about 2000 .ttr files so i want to make that process in batch using a script.
we need to reopen these script modified files using teeTreeOffice because the get maintained as new scientific litterature is published (we store such info in teeTrees at our company). The indiviual that maintain the teeTrees use teeTreeOffice to do so.
TXT_CODE_OM is a simple constant containing the string 'Code_OM'
i hope this will help you help me.
gracias
mCaron
[email protected]
Posted: Thu Jun 08, 2006 6:02 pm
by Tom
So, if I understand correctly, you just iterate over an existing tree, add some info and save it back to disk. If so, you don't need to use TDBTree, TTree should be sufficient. TDBTree is a descendant of TTree do display data from a database (eg in master-detail / parent-code situations).
Further, the loading of the in teeTreeOffice designed tree works correctly and
the error appears when you want to reload the modified inside teeTreeOffice? Am I correct in this assumption?
Which version of teeTree2 (the latest? ie the one accompanied with teeChart Pro v7.07?) are you using and which version of TeeTreeOffice?
I'll try to set up a similar code to find out what happens.
Regards,
tom
Posted: Thu Jun 08, 2006 7:50 pm
by Tom
Hi,
Could you try the following code and see if you get an error? This should give a correct result (at least on my pc).
Code: Select all
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, TeeProcs, TeeTree, StdCtrls;
type
TForm1 = class(TForm)
Tree1: TTree;
btnLoad: TButton;
btnModify: TButton;
btnSave: TButton;
OpenDialog1: TOpenDialog;
procedure btnLoadClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnModifyClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnLoadClick(Sender: TObject);
begin
if OpenDialog1.Execute then begin
Tree1.Clear;
LoadTreeFromFile(TCustomTree(Tree1),OpenDialog1.FileName);
end;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
var
BackupName : String;
begin
if FileExists(OpenDialog1.FileName) then
begin
BackupName := ExtractFileName(OpenDialog1.FileName);
BackupName := ChangeFileExt(BackupName, '.ttr.BAK');
DeleteFile(BackupName);
if not RenameFile(OpenDialog1.FileName, BackupName) then
raise Exception.Create('Unable to create backup file.');
SaveTreeToFile(TCustomTree(Tree1), OpenDialog1.FileName);
end;
end;
procedure TForm1.btnModifyClick(Sender: TObject);
var
i: integer;
tmpNode: TTreeNodeShape;
begin
// modify text / font
for i := 0 to Tree1.Shapes.Count - 1 do
begin
Tree1.Shapes[i].SimpleText := 'mod_of_'+Tree1.Shapes[i].SimpleText;
Tree1.Shapes[i].Font.Style := Tree1.Shapes[i].Font.Style + [fsBold];
end;
// add child to root if exists
tmpNode := nil;
if Tree1.Roots.Count > 0 then
tmpNode := Tree1.Roots[0].AddChild('new node!');
// modify new added node if exists
if (tmpNode <> nil) then
begin
tmpNode.Font.Style := tmpNode.Font.Style + [fsItalic];
tmpNode.Font.Color := clRed;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tree1.NoOwnerShapes := false;
Tree1.AssignParent := false;
end;
end.
Regards,
Tom.
Posted: Fri Jun 09, 2006 12:44 pm
by 7723130
hola Tom
you are quite right about the TDBTree issue. But i had already tried with a TTree and encountered the same problem.
I have also runned the code you sent me, and i still have the same problem when i try to reOpen the script modified tree using the teeTreeOffice.
I use teeTree version 2.1
and i use the version of teeTree office that was on steema's web site last tuesday.
I also use delphi 7
again, thanks for your sustained help.
mCaron
[email protected]
Posted: Fri Jun 09, 2006 3:40 pm
by Tom
mmm, this is really weird...
so you used the example code to modify a ttr, and then you reopened that one into TeeTreeOffice and you received an error? This works here without any problem...
Do you use a specific ttr? If possible please send me a ttr of yours so I can try it with that one.
Regards,
Tom.
Posted: Fri Jun 09, 2006 5:00 pm
by 7723130
Hola Tom
i will send you a teeTree built using an early version of teeTreeOffice (the teeTree was built in november 2002)
i ain't sure i have a good email address though.
thanks
mathieu caron
[email protected]
Posted: Fri Jun 09, 2006 6:01 pm
by Tom
i ain't sure i have a good email address though
tom @ steema . com
Code: Select all
the teeTree was built in november 2002
Have you tried using a tree built in the newer version?
Posted: Mon Jun 12, 2006 12:12 pm
by 7723130
no, i haven't tried with a newer version of the tee TreeOffice.
i'll try this out.
also, i will resend you a sample teeTree on which i am currently workink
again, mucho gracias Tom
mathieu caron
Posted: Mon Jun 12, 2006 10:03 pm
by Tom
Hi,
It seems to be caused by the accents on the chars (eg accent aigue). They are differently handled between Delphi versions? I've recompiled teeTreeOffice and this version doesn't gives the error anymore.
Regards,
tom