我现在把一个子窗体封装在一个dll中,在MDI窗体中也可以调用dll中的子窗体,当我加载dll并且窗体被创建以后(可以看的到),该窗体是fsMDIChild,这是却无法用Application.MainForm.ActiveMDIChild来调用该dll中的窗体,不知道是什么原因
dll工程
library Module;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Forms,
Windows,
Messages,
Classes,
uModule in 'uModule.pas' {frmModule};var
DLLApp: TApplication;
DLLScr: TScreen;function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
begin
Application := App;
Screen := Scr;
Application.CreateForm(TfrmModule, frmModule);
result:=frmModule;
end;procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
CreateDLLForm;begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;end.调用
unit uMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;type
InvokeDLLForm = function(App: TApplication; Scr: TScreen): TForm;
TfrmMain = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
DLL1: TMenuItem;
N2: TMenuItem;
procedure DLL1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
frmMain: TfrmMain;
DLLForm: TForm;implementation{$R *.dfm}procedure TfrmMain.DLL1Click(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;begin
DLLHandle := LoadLibrary('Module.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;
procedure TfrmMain.N2Click(Sender: TObject);
begin
ShowMessage(Application.MainForm.ActiveMDIChild.Name);
end;end.
执行ShowMessage(Application.MainForm.ActiveMDIChild.Name);出错,是什么原因啊
dll工程
library Module;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Forms,
Windows,
Messages,
Classes,
uModule in 'uModule.pas' {frmModule};var
DLLApp: TApplication;
DLLScr: TScreen;function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
begin
Application := App;
Screen := Scr;
Application.CreateForm(TfrmModule, frmModule);
result:=frmModule;
end;procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
CreateDLLForm;begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;end.调用
unit uMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;type
InvokeDLLForm = function(App: TApplication; Scr: TScreen): TForm;
TfrmMain = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
DLL1: TMenuItem;
N2: TMenuItem;
procedure DLL1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
frmMain: TfrmMain;
DLLForm: TForm;implementation{$R *.dfm}procedure TfrmMain.DLL1Click(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;begin
DLLHandle := LoadLibrary('Module.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;
procedure TfrmMain.N2Click(Sender: TObject);
begin
ShowMessage(Application.MainForm.ActiveMDIChild.Name);
end;end.
执行ShowMessage(Application.MainForm.ActiveMDIChild.Name);出错,是什么原因啊
2、show的操作最好放到DLL去做,返回值为TForm的好像只有Delphi才可以调用的,本来DLL是多维共享的东东,其他的开发平台也可以用的