procedure TDM.DataBase_OpenFile(Filename :
String);
var
RootNode : TTreeNode;
RootQuery : TABSQuery;
procedure AddChildNodes(ParentID: Integer; ParentNode: TTreeNode);
var
query : TABSQuery;
Node : TTreeNode;
begin
query := TABSQuery.Create(
nil);
try
query.DatabaseName := DM.Datasets.DatabaseName;
query.SessionName := DM.Datasets.SessionName;
query.SQL.Text := '
SELECT * FROM Datasets WHERE Tree_ParentID='+IntToStr(ParentID)+'
ORDER BY Tree_SortOrder';
query.Open;
while (
not query.EOF)
do begin
Node := LVMainForm.TV.Items.AddChild(ParentNode,
query.FieldByName('
Name').AsString);
Node.Data := TNodeData.Create;
Node.ImageIndex :=
query.FieldByName('
Tree_ImageIndex').AsInteger;
Node.SelectedIndex :=
query.FieldByName('
Tree_ImageSelect').AsInteger;
TNodeData(Node.Data).MDI_ID :=
query.FieldByName('
ID').AsInteger;
// Type als String aus DB lesen und in Auszählungstyp wandeln :-)
TNodeData(Node.Data).NodeTyp := TLVObjectTyp(GetEnumValue(TypeInfo(TLVObjectTyp),
query.FieldByName('
Typ').AsString));
TNodeData(Node.Data).MDIFile :=
query.FieldByName('
Filename').AsString;
AddChildNodes(
query.FieldByName('
ID').AsInteger, Node);
if Node.HasChildren
then
Node.Expanded :=
query.FieldByName('
Tree_Expanded').AsBoolean;
Node.Selected :=
query.FieldByName('
Tree_Selected').AsBoolean;
query.Next;
end;
query.Close;
finally
query.Free;
end;
end;
begin
DM.DB.DatabaseFileName := Filename;
DM.DB.Open;
DM.Datasets.Open;
DM.Windows.Open;
RootQuery := TABSQuery.Create(
nil);
try
RootQuery.DatabaseName := DM.Datasets.DatabaseName;
RootQuery.SessionName := DM.Datasets.SessionName;
RootQuery.SQL.Text := '
SELECT * FROM Datasets WHERE Tree_Depth=0 ORDER BY Tree_SortOrder';
RootQuery.Open;
while (
not RootQuery.EOF)
do begin
RootNode := LVMainForm.TV.Items.AddChild(
nil, RootQuery.FieldByName('
Name').AsString);
RootNode.Data := TNodeData.Create;
RootNode.ImageIndex := RootQuery.FieldByName('
Tree_ImageIndex').AsInteger;
RootNode.SelectedIndex := RootQuery.FieldByName('
Tree_ImageSelect').AsInteger;
TNodeData(RootNode.Data).MDI_ID := RootQuery.FieldByName('
ID').AsInteger;
// Type als String aus DB lesen und in Auszählungstyp wandeln :-)
TNodeData(RootNode.Data).NodeTyp := TLVObjectTyp(GetEnumValue(TypeInfo(TLVObjectTyp),
RootQuery.FieldByName('
Typ').AsString));
TNodeData(RootNode.Data).MDIFile := RootQuery.FieldByName('
Filename').AsString;
AddChildNodes(RootQuery.FieldByName('
ID').AsInteger, RootNode);
if RootNode.HasChildren
then
RootNode.Expanded := RootQuery.FieldByName('
Tree_Expanded').AsBoolean;
// RootNode.Selected := RootQuery.FieldByName('Tree_Selected').AsBoolean;
RootQuery.Next;
end;
RootQuery.Close;
finally
RootQuery.Free;
end;
end;