下面是一个静态调用DLL创建MDI子窗体的函数
-----------------------------------------------
var
Form1: TForm1;
procedure CallModule(ss:TADOConnection);stdcall;external 'ModuleDemo.dll';implementation{$R *.dfm}procedure TForm1.N111Click(Sender: TObject);
var s: tADOConnection;
begin
s := tADOConnection.Create(self);
CallModule(s);
end; initialization
Coinitialize(nil);
finalization
CoUninitialize;end.//////////////////////////////
DLL里的CallModule过程如下;
----------------------------------
var
DemoForm: TDemoForm;
procedure CallModule(ss:TADOConnection);stdcall;implementation{$R *.dfm}var AdoConn:Pointer;
procedure CallModule(SS:TADOConnection);
begin
AdoConn:=SS;
if not Assigned(DemoForm) then
begin
DemoForm:=TDemoForm.Create(Application);
DemoForm.Show;
end;
end;procedure TDemoForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := Cafree;
DemoForm := nil;
end;请问我怎样在主程序里调用DLL这个过程改成动态加载?
-----------------------------------------------
var
Form1: TForm1;
procedure CallModule(ss:TADOConnection);stdcall;external 'ModuleDemo.dll';implementation{$R *.dfm}procedure TForm1.N111Click(Sender: TObject);
var s: tADOConnection;
begin
s := tADOConnection.Create(self);
CallModule(s);
end; initialization
Coinitialize(nil);
finalization
CoUninitialize;end.//////////////////////////////
DLL里的CallModule过程如下;
----------------------------------
var
DemoForm: TDemoForm;
procedure CallModule(ss:TADOConnection);stdcall;implementation{$R *.dfm}var AdoConn:Pointer;
procedure CallModule(SS:TADOConnection);
begin
AdoConn:=SS;
if not Assigned(DemoForm) then
begin
DemoForm:=TDemoForm.Create(Application);
DemoForm.Show;
end;
end;procedure TDemoForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := Cafree;
DemoForm := nil;
end;请问我怎样在主程序里调用DLL这个过程改成动态加载?
type TGetTime = procedure(ss:TADOConnection);stdcall;
var
Handle: THandle;
GetTime: TGetTime;
s: TADOConnection;
begin
s := TADOConnection.Create(self);
Handle := LoadLibrary('ModuleDemo.dll');
if Handle <> 0 then
begin
@GetTime := GetProcAddress(Handle, 'CallModule');//CallModule 是动态连接库中的函数
if @GetTime <> nil then
begin
GetTime(s);
end;
FreeLibrary(Handle);
end;
end; 我是这样改的,运行时出现错误;
TCallModule = procedure(SS:TADOConnection);stdcall;
.....procedure TMainForm.LoadModule(AModuleName: PChar);
var
CallModule: TCallModule;
FPointer: TFarProc;
begin
LibHandle := LoadLibrary(AModuleName);
FPointer := GetProcAddress(LibHandle,'CallModule');
if FPointer<>nil then
begin
CallModule := FPointer;
CallModule(ADOConnection1);
end;
end;
上面利用调用DLL创建MDI子窗体的例子,
在公司运行正常,但昨晚在家机子上(同是D7)运行主程序时,提示"不能创建活动的子窗体"(把DLL里的窗体的FORMSYTLE属性改成fsNormal时,运行正常)真搞不明白为什么
procedure TForm1.N111Click(Sender: TObject);
var s: tADOConnection;
begin
s := tADOConnection.Create(self);
CallModule(s);
end;
才报错