unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Grids, DBGrids,
DB, StdCtrls, Buttons, ADODB;
type
THardware =
Record
Id : Integer;
IdParent: Integer;
end;
PHardware = ^THardware;
TMyHardware =
class(TForm)
ADOQuery1: TADOQuery;
ADODataSet1: TADODataSet;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
TreeView1: TTreeView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
MyHardware: TMyHardware;
implementation
{$R *.dfm}
procedure TMyHardware.Button1Click(Sender: TObject);
// diese Prozedur verschiebt den übergebenen Knoten and
// die richtige Position im TreeView
procedure MoveToParentNode(TheNode: TTreeNode);
var x : Integer;
begin
for x := 0
to TreeView1.Items.Count-1
do begin
if Assigned(TreeView1.Items[x].Data)
then begin
if PHardware(TreeView1.Items[x].Data).Id = PHardware(TheNode.Data).IdParent
then begin
TheNode.MoveTo(TreeView1.Items[x],naAddChild);
Break;
end;
end;
end;
end;
// Beginn von FillTreeView:
var Root,AktNode : TTreeNode;
i : Integer;
begin
ADOQuery1.First;
Root := TTreeNode.Create(TheView.Items);
Root.Text := '
Hardware';
Root.Data :=
nil;
while not ADOQuery1.EOF
do begin
AktNode := TTreeNode.Create(TreeView1.Items);
AktNode.Data := new(PHardware);
PHardware(AktNode.Data).Id := ADOQuery1.FieldByName('
IntArtKatId').AsInteger;
PHardware(AktNode.Data).IdParent := ADOQuery1.FieldByName('
IntArtKatParentID').AsInteger;
ADOQuery1.Next;
end;
for i := 0
to TreeView1.Items.Count-1
do begin
if Assigned(TreeView1.Items[i].Data)
then begin
if PHardware(TreeView1.Items[i].Data).IdParent <> 0
then MoveToParentNode(TreeView1.Items[i]);
end;
end;
end;
end.