Hier mal ein Stück vom Code...
Delphi-Quellcode:
...
type
TMyRecords = Record
FolderID : Integer;
ParentID : Integer;
FolderName : String;
ItemName : String;
end;
...
procedure TfrmMainProg.TreeViewInit;
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 PView(TreeView1.Items[x].Data).FolderID = PView(TheNode.Data).ParentID then begin
TheNode.MoveTo(TreeView1.Items[x], naAddChild);
Break;
end;
end;
end;
end;
var
Root,AktNode : TTreeNode;
i : Integer;
begin
ADOTable1.First;
TreeView1.Items.BeginUpdate;
Root := TTreeNode.Create(TreeView1.Items);
Root.Text := 'Root Dir';
Root.ImageIndex := IMG_NODE_ROOT;
//Root.Data := nil;
While NOT ADOTable1.eof do
begin
AktNode := TTreeNode.Create(TreeView1.Items);
AktNode.Data := new(PView);
PView(AktNode.Data).FolderID := ADOTable1.FieldByName('ID').AsInteger;
PView(AktNode.Data).ParentID := ADOTable1.FieldByName('ParentID').AsInteger;
PView(AktNode.Data).FolderName := ADOTable1.FieldByName('FolderName').AsString;
PView(AktNode.Data).ItemName := tblItems.FieldByName('ItemName').AsString;
/// Folder einlesen ...
with TreeView1.Items.Add(AktNode, PView(AktNode.Data).FolderName) do
begin
Data:=AktNode.Data;
ImageIndex := IMG_NODE_FOLDER_CLOSED;
SelectedIndex := IMG_NODE_FOLDER_OPEN;
end;
{ /// Das hier funzt irgendwie nicht, ///Files einlesen
with TreeView1.Items.AddChild(AktNode, PView(AktNode.Data).ItemName) do
begin
Data:=AktNode.Data;
ImageIndex := IMG_NODE_FILE_CLOSED;
SelectedIndex := IMG_NODE_FILE_OPEN;
end;
tblItems.Next;
}
ADOTable1.Next;
end;
for i := 0 to TreeView1.Items.Count -1 do
begin
if Assigned(TreeView1.Items[i].Data) then
begin
if PView(TreeView1.Items[i].Data).ParentID <> 0 then
MoveToParentNode(TreeView1.Items[i]);
end;
end;
TreeView1.FullCollapse;
TreeView1.Items.EndUpdate;
end;
Und die Procedure um eine neue Datei anzulegen und in die Datenbank zu schreiben lautet:
Delphi-Quellcode:
procedure TDataModule1.InsertFile (sFile :
string; iFileID :integer);
begin
With ADOQuery1
do
begin
Insert;
FieldByName('
FolderName').AsString := sFile;
FieldByName('
ParentID').AsInteger := iFileID;
//FieldByName('memFeld').xxxxxxxx??? ///hier die xml-Datei als Stream??? :wall:
Post;
end;
end;
Woher nehme ich den Wert für iFileID (Das Node, das ich gerade angelegt habe)? Welchen Wert also Index?