unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, IBDatabase, DB, IBQuery, IBCustomDataSet, IBTable,
ComCtrls, Menus, Grids, DBGrids;
type
TInfoC =
class
id:
integer
;
id_parent:
integer
;
NameC :
string
;
end
;
PTInfoC = ^TInfoC;
TForm1 =
class
(TForm)
TreeView1: TTreeView;
IBTable1: TIBTable;
IBQuery_output: TIBQuery;
IBDatabase1: TIBDatabase;
DataSource_output: TDataSource;
IBTransaction1: TIBTransaction;
IBQuery_new_cat: TIBQuery;
DataSource_new_cat: TDataSource;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
DBGrid1: TDBGrid;
procedure
FormCreate(Sender: TObject);
procedure
TreeBuild(T:TTreeNode);
private
public
end
;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure
TForm1
.
FormCreate(Sender: TObject);
var
InfoC: TInfoC;
U: TInfoC;
Catalog: TTreeNode;
dop:
integer
;
sss:
string
;
begin
IBQuery_output
.
Active:=
true
;
IBQuery_output
.
Params
.
ParamByName(
'parent'
).Value:=
0
;
IBQuery_output
.
Close;
IBQuery_output
.
Open;
IBQuery_output
.
Active:=
true
;
DBGrid1
.
Repaint();
DBGrid1
.
DataSource
.
DataSet
.
First;
while
not
DataSource_output
.
DataSet
.
Eof
do
begin
if
((DBGrid1
.
Columns[
0
].Field
.
AsInteger=
1
)
and
(DBGrid1
.
Columns[
3
].Field
.
AsInteger=
0
))
then
begin
InfoC:=TInfoC
.
Create;
InfoC
.
id:=DBGrid1
.
Columns[
0
].Field
.
AsInteger ;
InfoC
.
NameC:=DBGrid1
.
Columns[
1
].Field
.
AsString;
InfoC
.
id_parent:=
0
;
Catalog:=TreeView1
.
Items
.
AddObject(
nil
,DBGrid1
.
Columns[
1
].Field
.
Text, @InfoC);
end
;
DataSource_output
.
DataSet
.
Next;
end
;
TreeBuild(Catalog);
end
;
procedure
TForm1
.
TreeBuild( T: TTreeNode);
var
InfoC :TInfoC;
ttt:^TInfoC;
NewInfoC :
array
of
TInfoC;
Catalogs, C : TTreeNode;
dop,i,parent,countlist:
integer
;
index_first, index_last:
integer
;
sss:
string
;
cT:TTreeNode;
begin
parent := (PTInfoC(T
.
data))^.id;
IBQuery_output
.
Active:=
false
;
IBQuery_output
.
Params
.
ParamByName(
'parent'
).AsInteger:=parent;
IBQuery_output
.
Close;
IBQuery_output
.
Open;
IBQuery_output
.
Active:=
true
;
DBGrid1
.
Repaint();
if
IBQuery_output
.
RecordCount>
0
then
begin
SetLength(NewInfoC, IBQuery_output
.
RecordCount);
i:=
0
;
while
not
DataSource_output
.
DataSet
.
Eof
do
begin
if
( DBGrid1
.
Columns[
3
].Field
.
AsInteger=parent)
then
begin
NewInfoC[i]:=TInfoC
.
Create;
NewInfoC[i].id:=DBGrid1
.
Columns[
0
].Field
.
AsInteger ;
NewInfoC[i].NameC:=DBGrid1
.
Columns[
1
].Field
.
AsString;
NewInfoC[i].id_parent:=parent;
TreeView1
.
Items
.
AddChildObject(T,DBGrid1
.
Columns[
1
].Field
.
Text, @NewInfoC[i]) ;
i:=i+
1
;
end
;
DataSource_output
.
DataSet
.
Next;
end
;
cT:= (T
.
getFirstChild);
while
cT<>
nil
do
begin
cT:=cT
.
getNextSibling;
end
;
end
;
end
;
end
.