type
Tdmpkg = class(TDataModule)
SQLCon: TSQLConnection;
private
protected
function GetCon: TSQLConnection;
public
{ Public declarations }
end;
var
dmpkg: Tdmpkg;
implementation
{$R *.dfm}
function Tdmpkg.GetCon: TSQLConnection;
begin
Result := SQLCon;
end;
initialization
RegisterClass(Tdmpkg);
finalization
UnRegisterClass(Tdmpkg);
end.
——————————————dm的引用——————————
unit DMIntrpk;
interface
uses
SqlExpr,DBXpress;
type
IDMpk = Interface
['{AA5658B0-9D55-48A2-A719-37A1D638FCD5}']
function GetCon: TSQLConnection;
end;
implementation
end.
————————————————mainform——————————
unit uMain;
procedure TForm1.FormCreate(Sender: TObject);
begin
FpkHandle := LoadPackage('1.bpl');
if FpkHandle = 0 then
ShowMessage('Can not load package dbmodu.bpl');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SQLDataSet1.SQLConnection := nil;
FpkDM := nil;
if FpkHandle <> 0 then
UnloadPackage(FpkHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
AClass: TComponentClass;
begin
if FpkHandle <> 0 then
begin
AClass := TComponentClass(GetClass('TDMpk'));
if AClass <> nil then
begin
FpkDM := AClass.Create(nil) as IDMPk;
SQLDataSet1.SQLConnection := FpkDM.GetCon;
SQLDataSet1.Active:=true;
ClientDataSet1.Active:=true;
end;
end;
end;
end.