Page 1 of 1

Change ChildManager at runtime

Posted: Sun Apr 11, 2010 4:56 pm
by 10551078
Hi,
Delph 2007 and Teetree2 included Teechart Pro VCL 8.04

I try change presentation of Tree by (Explorer, Left , Top or ListView) , at runtime but i have exception.
What is the best practice in this subject ??

My code ================================================================


function TreePrepareManager(ATree:TTree;AChildManager:TObject):integer;
begin
if ATree=nil then exit;
try
// Typ de tree Explorateur ; top ; Left ; ListView (PB not ancestor common!!)
if (AChildManager is TTreeExplorerAlignChild) then
ATree.ChangeManager(AChildManager as TTreeExplorerAlignChild)
else if AChildManager is TTreeTopBottomAlignChild then
ATree.ChangeManager(AChildManager as TTreeTopBottomAlignChild)
else if AChildManager is TTreeLeftRightAlignChild then
ATree.ChangeManager(AChildManager as TTreeLeftRightAlignChild)
else if AChildManager is TTreeListViewAlignChild then
ATree.ChangeManager(AChildManager as TTreeListViewAlignChild);
Except
CT_ERR.Push('U_TreeEfc.pas : Procedure PrepareChildManager'); Raise; // exception vioalion access !!!
End;
end;

in my forms========================================

constructor TFrameEfcTree.Create(AOwner: TComponent);
begin
inherited;
// Format of the tree
ChildExplorateur :=TTreeExplorerAlignChild.Create;
ChildTop :=TTreeTopBottomAlignChild.Create;
ChildLeft :=TTreeLeftRightAlignChild.Create;
ChildList :=TTreeListViewAlignChild.Create;

Tree1.AssignParent:=True;
ChildEnCours := ChildExplorateur; // ChildEnCours is Tobject

end;

procedure TFrameEfcTree.BtExploClick(Sender: TObject);
begin

Tree1.Clear;
ChildEnCours := ChildExplorateur;
TreePrepareManager(Tree1, ChildEnCours );
end;

procedure TFrameEfcTree.BtLeftClick(Sender: TObject);
begin
Tree1.Clear;
ChildEnCours := ChildLeft;
TreePrepareManager(Tree1, ChildEnCours );
end;


But, in first test is OK, but if change 2 o 3 > exception !!

Re: Change ChildManager at runtime

Posted: Mon Apr 12, 2010 11:19 am
by yeray
Hi mivchart,

Could you please send us a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.

Re: Change ChildManager at runtime

Posted: Mon Apr 12, 2010 1:44 pm
by 10551078
Ok, with sample project.

Re: Change ChildManager at runtime

Posted: Wed Apr 14, 2010 7:34 am
by 10551078
Do you have solution for me, with example above !

Re: Change ChildManager at runtime

Posted: Thu Apr 15, 2010 1:54 pm
by yeray
Hi mivchart,

Thanks for the project. We could reproduce the problem and we tried to analyse what's wrong but I'm afraid we couldn't find it.
I've added it to the defect list to be revised deeper so it can be fixed in future releases (TV52014798).

Re: Change ChildManager at runtime

Posted: Thu Apr 15, 2010 3:00 pm
by 10551078
ok,

ok, I'll do differently in this case

Re: Change ChildManager at runtime

Posted: Fri Apr 16, 2010 2:35 pm
by 10551078
Hi,

i have a solution to every change made in the format, you must recreate a ChilManger, without releasing the previous !
I think the release is done internally

It's simple and it works
I create a type to simplify my code


type TTreeFmtType=(TreeFmtExplo,TreeFmtTop,TreeFmtLeft,TreeFmtList);

//=======================================

procedure TFrameEfcTree.TreeChangeFormat;
begin
try
//change la Forme du Tree
case TreeFormat of
TreeFmtExplo: Tree1.ChangeManager(TTreeExplorerAlignChild.Create);
TreeFmtTop: Tree1.ChangeManager(TTreeTopBottomAlignChild.Create);
TreeFmtLeft: Tree1.ChangeManager(TTreeLeftRightAlignChild.Create);
TreeFmtList: Tree1.ChangeManager(TTreeListViewAlignChild.Create);
end; //case

except
On E:Exception do Showmessage(E.Message);
end;
end;