unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADODB,
DB, ComCtrls, StdCtrls;
type
TForm1 =
class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOTable1: TADOTable;
TreeView1: TTreeView;
ListView1: TListView;
ListBox1: TListBox;
procedure FormShow(Sender: TObject);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
private
function DatenverbindungHerstellen(): boolean;
procedure FillTreeview;
procedure FillListbox;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.FillTreeview;
var
Node: TTreenode;
begin
//Bereits vorhandene Knotenelemente (Items) werden gelöscht:
Treeview1.items.clear;
ADOQuery1.close;
ADOQuery1.SQL.clear;
ADOQuery1.SQL.Add('
Select * from MVO_Sparten');
ADOQuery1.Open;
While not ADOQuery1.Eof
do begin
Node := Treeview1.items.add(
nil,ADOQuery1.FieldValues['
Sparten_Bezeichnung'] + '
(' + ADOQuery1.FieldValues['
Sparten_Abkürzung'] + '
)');
Node.ImageIndex := 0;
// Verwende ich zum Speichern der Tabellen-ID je Knotenelement:
Node.StateIndex := ADOQuery1.FieldValues['
Spartennummer'];
ADOQuery1.Next;
end;
AdoQuery1.Close;
end;
procedure Tform1.FillListbox;
begin
Listbox1.items.clear;
ADOQuery1.close;
ADOQuery1.SQL.clear;
ADOQuery1.SQL.Add('
Select * from MVO_Notenverzeichnis');
ADOQuery1.Open;
While not ADOQuery1.Eof
do begin
Listbox1.Items.add(ADOQuery1.FieldValues['
Komponistnachname']) ;
ADOQuery1.Next;
end;
Adoquery1.close;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Datenverbindungherstellen();
Filltreeview();
Filllistbox();
end;
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
LI: TListitem;
begin
Listview1.items.clear;
ADOQuery1.close;
ADOQuery1.SQL.clear;
ADOQuery1.SQL.Add('
Select * from MVO_Notenverzeichnis where Spartennummer = ' + inttostr(Node.stateindex));
ADOQuery1.Open;
While not ADOQuery1.Eof
do begin
LI := Listview1.items.add;
LI.caption := ADOQuery1.FieldValues['
Name'];
// LI.subitems.add(ADOQuery1.FieldValues['PR_Bezeichnung']);
ADOQuery1.Next;
end;
AdoQuery1.Close;
end;
function tform1.DatenverbindungHerstellen(): boolean;
var
Provider, DataProvider, DataSource:
string;
begin
Provider := '
MSDataShape.1';
DataProvider := '
Microsoft.Jet.OLEDB.4.0';
DataSource := extractfilepath(application.ExeName) + '
MVerein.mdb';
if fileexists(DataSource)
then begin
if ADOConnection1.Connected
then ADOConnection1.Close;
ADOConnection1.ConnectionString := '
Provider=' + Provider + '
;Data Provider=' + DataProvider + '
;Data Source=' + DataSource;
try
ADOConnection1.Connected := true;
result := true;
except
result := false;
end;
end else begin
result := false;
end;
end;
end.