以下是我的原代码:
=============================================== ======================================
DPR单元代码
programMdiform;
verwendet
Formulare,
UMdiformin´UMdiform.pas´{Mainform},
UDMin´UDM.pas´{GlobalDM:TDataModule},
UFunin´UFun.pas´;
{$R*.res}
beginnen
Application.Initialize;
Application.CreateForm(TMainform,Mainform);
Application.Run;
Ende.
=============================================== ===========================================
主窗体代码:
unitUMdiform;
Schnittstelle
verwendet
Windows, Nachrichten, SysUtils, Varianten, Klassen, Grafiken, Steuerelemente, Formulare,
Dialoge,Udm,StdCtrls;
Typ
TMainform=class(TForm)
Button1:TButton;
procedureButton1Click(Sender:TObject);
procedureFormCreate(Sender:TObject);
Privat
{Privatedeclarations}
öffentlich
MyHandle:HWND;
{Öffentliche Erklärungen}
Ende;
var
Hauptform:TMainform;
Typ
T_ShowTestMng=function(varadm:TMainform):Boolean;StdCall;
Durchführung
{$R*.dfm}
procedureTMainform.Button1Click(Sender:TObject);
var
Lib_:THandle;
_ShowTestMng:T_ShowTestMng;
beginnen
Lib_:=LoadLibrary(pchar(´MdiChild.dll´));
versuchen
@_ShowTestMng:=GetProcAddress(Lib_,´_ShowTestMng´);
ifnot(@_ShowTestMng=nil)then
_ShowTestMng(Mainform);
Endlich
FreeLibrary(Lib_);
Ende;
Ende;
procedureTMainform.FormCreate(Sender:TObject);
beginnen
MyHandle:=Application.Handle;
Ende;
Ende.
=============================================== ==========================================
Download der DLL-Datei:
BibliothekMdiChild;
verwendet
ShareMem,
UMdiform,//此单元为父窗体单元,在顶目设置中我已经设置了搜索此单元在路径。
Formulare,
SysUtils,
Klassen,
UChildin´UChild.pas´{FrmChild};//FrmChild子窗体的FormStyle属性为FsMDIChild
{$R*.res}
function_ShowTestMng(varadm:TMainform):Boolean;StdCall;
beginnen
Ergebnis:=true;
Application.Handle:=adm.MyHandle;
Application.CreateForm(TFrmChild,FrmChild);//程序就就出错在此:出错原因是:Cannotcreateform.NoMDIFormsarecurrentlyactive.
FrmChild.Show;
Ende;
Exporte
_ShowTestMng;
Ende.