Page 1 of 1

TDBTree Code Parent - Master Detail - sample code

Posted: Mon Oct 03, 2011 2:48 pm
by 7728351
I have implemented a TDBTree using one dataset with a code field and a parent field pointing to it.
Similar to TDBTree Wizard sample code (Database Tree Wizard).

Now I would like to add one additional level to the end of the tree based upon a master - detail relationship.

Could you please provide some sample code on how to add this additional level.

Do I have to use Layout?

Sample code:
DbTree1.DataSet := dm_main.qry_tree_structure; // some table
dm_main.qry_tree_structure.Open;
DbTree1.Layout[0].codefield := 'CODE_ID';
DbTree1.Layout[0].Parentfield := 'PARENT_ID';
DbTree1.Layout[0].fields := 'NAME';
DbTree1.Refresh;

The number of levels in the tree is not fixed, for some data you see a total of 4 levels, for some data a total of 5 levels, for some data a total of 6 levels.

Table1.CODE_ID is linked using a master detail relationship to Table2. I would like to display Table2.name one level below the tree end.

Thank you in advance for your reaction.

Re: TDBTree Code Parent - Master Detail - sample code

Posted: Wed Oct 05, 2011 2:16 pm
by 7728351
Good afternoon,

Using Parent / Code relationship Delphi code we solved this issue by changing the SQL - query using UNION ALL.

select ...
from table1
UNION ALL
select ...
from table1, table2
where ... ( join )

Best regards,

Erik

Re: TDBTree Code Parent - Master Detail - sample code

Posted: Thu Oct 06, 2011 8:26 am
by yeray
Hello Erik,

I was going to ask you for more details to understand better your needs, but I'm glad to hear you found how to achieve it.