problems trying to save TDBTree and reopen with teeTreeOffic

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
mCaron
Newbie
Newbie
Posts: 5
Joined: Mon Feb 04, 2002 5:00 am

problems trying to save TDBTree and reopen with teeTreeOffic

Post by mCaron » Thu Jun 08, 2006 2:31 pm

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]

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Thu Jun 08, 2006 3:26 pm

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

mCaron
Newbie
Newbie
Posts: 5
Joined: Mon Feb 04, 2002 5:00 am

Post by mCaron » Thu Jun 08, 2006 3:35 pm

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]

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Thu Jun 08, 2006 6:02 pm

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

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Thu Jun 08, 2006 7:50 pm

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.

mCaron
Newbie
Newbie
Posts: 5
Joined: Mon Feb 04, 2002 5:00 am

Post by mCaron » Fri Jun 09, 2006 12:44 pm

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]

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Fri Jun 09, 2006 3:40 pm

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.

mCaron
Newbie
Newbie
Posts: 5
Joined: Mon Feb 04, 2002 5:00 am

Post by mCaron » Fri Jun 09, 2006 5:00 pm

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]

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Fri Jun 09, 2006 6:01 pm

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?

mCaron
Newbie
Newbie
Posts: 5
Joined: Mon Feb 04, 2002 5:00 am

Post by mCaron » Mon Jun 12, 2006 12:12 pm

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

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Mon Jun 12, 2006 10:03 pm

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

Post Reply