unit Unit1;
interface
uses
Classes, Controls, Forms, DBGrids, IBDatabase, IBCustomDataSet, IBQuery,
DBTables, StdCtrls, Grids,
Db;
type
RechteSeite =
interface
procedure Open;
procedure SetQuerySQL(GSQL : TStrings);
function GetQuerySQL : TStrings;
function GetConnection : TCustomConnection;
end;
{ LinkeSeite = class(TComponent) //TDataSet
private
Implementor : RechteSeite;
public
procedure Open; virtual; abstract;
procedure SetQuery(GSQL : TStrings); virtual; abstract;
function GetQuery : TStrings; virtual; abstract;
function GetConnection : TCustomConnection; virtual; abstract;
published
property SQL: TStrings read GetQuery write SetQuery;
end; }
SpezLinkeSeite =
class(TDataSet)
//LinkeSeite
constructor create(Welchen : Byte; AOwner: TComponent; DataBaseName :
String);
private
Implementor : RechteSeite;
//Eigentlich in LinkeSeite
procedure SetQuery(Value: TStrings);
function GetQuery : TStrings;
public
procedure Open;
function GetConnection : TCustomConnection;
published
property SQL: TStrings
read GetQuery
write SetQuery;
end;
KonkreteIB =
class(TIBQuery, RechteSeite)
constructor create(AOwner : TComponent; Connection : TIBDatabase);
overload;
private
constructor Create(AOwner : TComponent);
overload;
override;
public
constructor create(AOwner : TComponent; DataBaseName :
String);
overload;
procedure SetQuerySQL(GSQL : TStrings);
function GetQuerySQL : TStrings;
function GetConnection : TCustomConnection;
end;
KonkreteTQuery =
class(TQuery, RechteSeite)
constructor create(AOwner : TComponent; DataBaseName :
String);
overload;
public
procedure SetQuerySQL(GSQL : TStrings);
function GetQuerySQL : TStrings;
function GetConnection : TCustomConnection;
end;
TForm1 =
class(TForm)
DBGrid1: TDBGrid;
Button1: TButton;
DataSource1: TDataSource;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
LSQ : SpezLinkeSeite;
//Eigentlich soll hier "LSQ : LinkeSeite;" genommen werden.
procedure QueryAbfrage;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
constructor KonkreteTQuery.create(AOwner : TComponent; DataBaseName :
String);
begin
inherited create(AOwner);
self.DatabaseName := DataBaseName;
end;
procedure KonkreteTQuery.SetQuerySQL(GSQL : TStrings);
begin
self.SQL := GSQL;
end;
function KonkreteTQuery.GetQuerySQL : TStrings;
begin
Result := self.SQL;
end;
function KonkreteTQuery.GetConnection : TCustomConnection;
begin
Result := self.DataBase;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor KonkreteIB.create(AOwner : TComponent; Connection : TIBDatabase);
begin
inherited create(AOwner);
if not assigned(Connection)
then exit
//hier richtigen abbruch hin
else Self.Database := Connection;
Create(AOwner);
end;
constructor KonkreteIB.create(AOwner : TComponent; DataBaseName :
String);
begin
inherited create(AOwner);
Self.DataBase := TIBDataBase.create(AOwner);
Self.DataBase.DataBaseName := DataBaseName;
Create(AOwner);
end;
constructor KonkreteIB.Create(AOwner : TComponent);
begin
self.Transaction := TIBTransaction.create(AOwner);
self.Database.Connected := true;
self.Transaction.DefaultDatabase := self.DataBase;
self.Transaction.Active := true;
end;
procedure KonkreteIB.SetQuerySQL(GSQL : TStrings);
begin
self.SQL := GSQL;
end;
function KonkreteIB.GetQuerySQL : TStrings;
begin
Result := self.SQL;
end;
function KonkreteIB.GetConnection : TCustomConnection;
begin
Result := self.DataBase;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor SpezLinkeSeite.create(Welchen : Byte; AOwner: TComponent; DataBaseName :
String);
begin
inherited create(AOwner);
case Welchen
of
1 : Implementor := KonkreteIB.create(AOwner, DataBaseName);
2 : Implementor := KonkreteTQuery.create(AOwner, DataBaseName);
else Exit;
//Hier richtigen Abbruch
end;
end;
procedure SpezLinkeSeite.SetQuery(Value: TStrings);
begin
Implementor.SetQuerySQL(Value);
end;
function SpezLinkeSeite.GetQuery : TStrings;
begin
Result := Implementor.GetQuerySQL;
end;
procedure SpezLinkeSeite.open;
begin
Implementor.open;
end;
function SpezLinkeSeite.GetConnection : TCustomConnection;
begin
//
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject);
begin
LSQ := SpezLinkeSeite.create(1, Form1, '
C:\Programme\Borland\InterBase\bin\PUS');
QueryAbfrage;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
LSQ := SpezLinkeSeite.create(2, Form1, '
IBLocal');
QueryAbfrage;
end;
procedure TForm1.QueryAbfrage;
begin
LSQ.SQL.Clear;
LSQ.SQL.Append('
select * from impro');
LSQ.Open;
DataSource1.DataSet := LSQ;
{ <-- Hier liegt das Problem. }
end;
end.