unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComObj, ComCtrls, ADOX_TLB, ADODB_TLB, XPMan, StdCtrls, Buttons;
type
TForm1 =
class(TForm)
StatusBar1: TStatusBar;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
XPManifest1: TXPManifest;
EditMDB: TEdit;
Button1: TButton;
TabSheet2: TTabSheet;
GroupBox1: TGroupBox;
MemoLog: TMemo;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button2: TButton;
Button3: TButton;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
ListBox1: TListBox;
Label7: TLabel;
Label8: TLabel;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure TabSheet2Show(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
resourcestring
cCONNECTSTRING='
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
procedure TForm1.Button1Click(Sender: TObject);
var
aCatalog : _Catalog;
aTable : _Table;
AColumn : _ColumnDisp;
aIdx : _Index;
sDBPath :
String;
sDS :
String;
vColName : OLEVariant;
begin
MemoLog.Lines.Clear;
sDBPath:=EditMDB.Text;
if FileExists(sDBPath)
then
begin
DeleteFile(sDBPath);
memoLog.Lines.Add(Format('
Datenbankdatei %S gelöscht',[sDBPath]));
end;
aCatalog:=CoCatalog.Create;
MemoLog.Lines.Add('
Catalog erstellen...');
sDS:=aCatalog.Create(Format('
%s%s',[cCONNECTSTRING, sDBPath]));
MemoLog.Lines.Add(sDS);
aTable:=CoTable.Create;
MemoLog.Lines.Add('
Table erstellen...');
aTable.ParentCatalog:=aCatalog;
aTable.
Name:='
Kunden';
//Spalte 1 = Primärschlüssel
vColName:='
KundenNummer';
aTable.Columns.Append(vColName,adVarWChar,30);
aColumn:=aTable.Columns.Item[vColName]
as _ColumnDisp;
aColumn.Properties['
Description'].Value:='
Name des Künstlers';
MemoLog.Lines.Add('
Spalte 1 hinzugefügt...');
//Primärschlüssel hinzufügen
aTable.Keys.Append('
Kundennummer',adKeyPrimary,vColName,'
','
');
MemoLog.Lines.Add('
Spalte 1 als Primärschlüssel definiert...');
//Spalte 2 = Zeichenfeld das auch Leer bleiben kann
vColName:='
eMail';
aTable.Columns.Append(vColName,adVarWChar, 20);
aColumn:=aTable.Columns.Item[vColName]
as _ColumnDisp;
aColumn.Properties['
Description'].Value:='
eMail Adresse des Kunden';
aColumn.Properties['
Jet OLEDB:Allow Zero Length'].Value:=True;
aColumn.Properties['
Default'].Value:='
(unbekannt)';
MemoLog.Lines.Add('
Spalte 2 hinzugefügt...');
//Index auf die Spalte 2 legen
aIdx:=CoIndex.Create;
with aIdx
do
begin
Name:='
IdxMail';
Columns.Append(aColumn.
Name, aColumn.type_,aColumn.DefinedSize);
PrimaryKey:=False;
Unique:=False;
end;
aTable.Indexes.Append(aIdx,EmptyParam);
MemoLog.Lines.Add('
Index IdxMail hinzugefügt...');
//Spalte 3 - Zeichenfeld mit "Erforderlich = Nein"
vColName:='
Telefon';
aTable.Columns.Append(vColName,adVarWChar, 15);
aColumn:=aTable.Columns.Item[vColName]
as _ColumnDisp;
aColumn.Properties['
Description'].Value:='
Telefonnummer des Kunden';
aColumn.Properties['
Nullable'].Value:=True;
MemoLog.Lines.Add('
Spalte 3 jinzugefügt...');
//Tabelle hinzufügen
aCatalog.Tables.Append(aTable);
MemoLog.Lines.Add('
...Fertig');
end;
procedure TForm1.Button4Click(Sender: TObject);
var
aConnection : _Connection;
aCatalog : _Catalog;
aTable : _Table;
swConnString : WideString;
iRecCount : Integer;
i : Integer;
begin
//Schritt 1 - Das Connection Objekt
aConnection:=CoConnection.Create;
swConnString:='
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Stamm.mdb; Persist Security Info=False';
aConnection.Open(swConnString,'
','
',-1);
//Schritt 2 - Das Catalog Objekt
aCatalog:=CoCatalog.Create;
aCatalog.Set_ActiveConnection(aConnection);
iRecCount:=aCatalog.Tables.Get_Count;
Label5.Caption:=IntToStr(iRecCount);
ListBox1.Items.Clear;
for i:=0
to iRecCount-1
do
begin
aTable:=aCatalog.Tables.Item[i];
ListBox1.Items.Add(aTable.
Name);
end;
aConnection.Close;
end;
procedure TForm1.TabSheet2Show(Sender: TObject);
var
aCon : _Connection;
aRS : _Recordset;
cCS : WideString;
sData :
String;
begin
cCS:='
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Stamm.mdb';
aCon:=CoConnection.Create;
aCon.Open(cCs,'
','
',adConnectUnspecified);
try
aRS:=aCon.OpenSchema(adSchemaTables,EmptyParam,EmptyParam);
while not aRS.EOF
do
begin
sData:=Format('
%s,&S,%s',[aRS.Fields[0].Value,aRS.Fields[1].Value,aRS.Fields[2].Value]);
ListBox1.Items.Clear;
ListBox1.Items.Add(sData);
//Edit1.Text:=aRS.Fields[0].Value;
aRS.MoveNext;
end;
finally
aCon.Close;
end;
end;
end.