Z
zyx1122
Unregistered / Unconfirmed
GUEST, unregistred user!
如何在Dll中调用DataModule? 哪位高人可以指点一下? to : Shd, rester 到目前为止,整个Delphi世界只有你们二位知道如何解决此问题。你们可不可以解释的详细一些? 终于算是解决了. 如果大家也需要这样的要求可以看看, 我过几天才把他Close (70分)<br />我用delphi写了一个dll
希望在此dll中调用DataModule, 如何做到?
TDataModule.Create(AOwer TComponent)需要参数AOwer(TComponent)
而我在dll中写的类ICtlVehicle没有继承TComponent(设计要求), 我就无法创建一个TDataModule.
///////////////////////// ICtlVehicle.pas /////////////////////
unit ICtlVehicle;
interface
uses
classes;
type
ICtlVehicleInOut = class;
TCtlVehicleInOutClass = class of ICtlVehicleInOut;
// ICtlVehicleInOut = class(TComponent)
ICtlVehicleInOut = class
protected
public
// constructor Create(AOwner: TComponent);
override;
constructor Create;
virtual;
end;
// TCtlVehicleInOutClass = class of ICtlVehicleInOut;
implementation
{ ICtlVehicleInOut }
//constructor ICtlVehicleInOut.Create(AOwner: TComponent);
constructor ICtlVehicleInOut.Create;
begin
inherited;
end;
end.
///////////////////////// uImpCtlVehicle /////////////////////////////////
unit uImpCtlVehicle;
interface
uses
ICtlVehicle,
Classes,
SysUtils,
uDMC, {uDMC是一个DataModule, 文件是uDMC.pas}
Dialogs;
type
TCtlVehicleInOut = class(ICtlVehicleInOut)
private
m_dm : TdmClient;
public
// constructor Create(AOwner: TComponent);
override;
constructor Create;
override;
end;
implementation
{ TCtlVehicleInOut }
//constructor TCtlVehicleInOut.Create(AOwner: TComponent);
constructor TCtlVehicleInOut.Create;
begin
inherited;
//????如何创建DataModule??????
//m_dm := ????;
//如果用m_dm := TdmClient.Create(需要参数),但无参数
if (m_dm = nil) then
begin
ShowMessage('m_dm is null');
end;
end;
end.
////////////////////// uDMC.pas //////////////////////////
unit uDMC;
interface
uses
SysUtils, Classes, DB, DBClient, MConnect;
type
TdmClient = class(TDataModule)
conn: TDCOMConnection;
cdsVehicle: TClientDataSet;
dsVehicle: TDataSource;
cdsVehiclecard_no: TStringField;
cdsVehiclevehicle_no: TStringField;
cdsVehiclevehicle_type: TStringField;
cdsVehiclein_time: TDateTimeField;
cdsVehicleout_time: TDateTimeField;
cdsVehiclein_picture: TBlobField;
cdsVehicleout_picture: TBlobField;
function GetDataModule : TdmClient;
private
{ Private declarations }
public
end;
var
dmClient: TdmClient;
implementation
{$R *.dfm}
end.
希望在此dll中调用DataModule, 如何做到?
TDataModule.Create(AOwer TComponent)需要参数AOwer(TComponent)
而我在dll中写的类ICtlVehicle没有继承TComponent(设计要求), 我就无法创建一个TDataModule.
///////////////////////// ICtlVehicle.pas /////////////////////
unit ICtlVehicle;
interface
uses
classes;
type
ICtlVehicleInOut = class;
TCtlVehicleInOutClass = class of ICtlVehicleInOut;
// ICtlVehicleInOut = class(TComponent)
ICtlVehicleInOut = class
protected
public
// constructor Create(AOwner: TComponent);
override;
constructor Create;
virtual;
end;
// TCtlVehicleInOutClass = class of ICtlVehicleInOut;
implementation
{ ICtlVehicleInOut }
//constructor ICtlVehicleInOut.Create(AOwner: TComponent);
constructor ICtlVehicleInOut.Create;
begin
inherited;
end;
end.
///////////////////////// uImpCtlVehicle /////////////////////////////////
unit uImpCtlVehicle;
interface
uses
ICtlVehicle,
Classes,
SysUtils,
uDMC, {uDMC是一个DataModule, 文件是uDMC.pas}
Dialogs;
type
TCtlVehicleInOut = class(ICtlVehicleInOut)
private
m_dm : TdmClient;
public
// constructor Create(AOwner: TComponent);
override;
constructor Create;
override;
end;
implementation
{ TCtlVehicleInOut }
//constructor TCtlVehicleInOut.Create(AOwner: TComponent);
constructor TCtlVehicleInOut.Create;
begin
inherited;
//????如何创建DataModule??????
//m_dm := ????;
//如果用m_dm := TdmClient.Create(需要参数),但无参数
if (m_dm = nil) then
begin
ShowMessage('m_dm is null');
end;
end;
end.
////////////////////// uDMC.pas //////////////////////////
unit uDMC;
interface
uses
SysUtils, Classes, DB, DBClient, MConnect;
type
TdmClient = class(TDataModule)
conn: TDCOMConnection;
cdsVehicle: TClientDataSet;
dsVehicle: TDataSource;
cdsVehiclecard_no: TStringField;
cdsVehiclevehicle_no: TStringField;
cdsVehiclevehicle_type: TStringField;
cdsVehiclein_time: TDateTimeField;
cdsVehicleout_time: TDateTimeField;
cdsVehiclein_picture: TBlobField;
cdsVehicleout_picture: TBlobField;
function GetDataModule : TdmClient;
private
{ Private declarations }
public
end;
var
dmClient: TdmClient;
implementation
{$R *.dfm}
end.