delphi中一個值得年夜家來斟酌的DLL成績。本站提示廣大學習愛好者:(delphi中一個值得年夜家來斟酌的DLL成績)文章只能為提供參考,不一定能成為您想要的結果。以下是delphi中一個值得年夜家來斟酌的DLL成績正文
以下是我的原代碼:
==========================================================================================
DPR 單位代碼
program Mdiform;
uses
Forms,
UMdiform in ´UMdiform.pas´ {Mainform},
UDM in ´UDM.pas´ {GlobalDM: TDataModule},
UFun in ´UFun.pas´;
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainform, Mainform);
Application.Run;
end.
===============================================================================================
主窗體代碼:
unit UMdiform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Udm,StdCtrls;
type
TMainform = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
MyHandle:HWND;
{ Public declarations }
end;
var
Mainform: TMainform;
type
T_ShowTestMng=function (var adm:TMainform) : Boolean; StdCall;
implementation
{$R *.dfm}
procedure TMainform.Button1Click(Sender: TObject);
var
Lib_ :THandle;
_ShowTestMng :T_ShowTestMng;
begin
Lib_:=LoadLibrary(pchar(´MdiChild.dll´));
try
@_ShowTestMng:=GetProcAddress(Lib_,´_ShowTestMng´);
if not(@_ShowTestMng=nil) then
_ShowTestMng(Mainform);
finally
FreeLibrary(Lib_);
end;
end;
procedure TMainform.FormCreate(Sender: TObject);
begin
MyHandle:=Application.Handle;
end;
end.
==============================================================================================
子窗體DLL代碼:
library MdiChild;
uses
ShareMem,
UMdiform, //此單位為父窗體單位,在頂目設置中我曾經設置了搜刮此單位在途徑。
Forms,
SysUtils,
Classes,
UChild in ´UChild.pas´ {FrmChild};//FrmChild子窗體的FormStyle屬性為FsMDIChild
{$R *.res}
function _ShowTestMng(var adm:TMainform) : Boolean; StdCall;
begin
result:=true;
Application.Handle:=adm.MyHandle;
Application.CreateForm(TFrmChild,FrmChild); //法式就失足在此:失足緣由是:Cannot create form. No MDI Forms are currently active.
FrmChild.Show;
end;
exports
_ShowTestMng;
end.