Z
zhwwlp
Unregistered / Unconfirmed
GUEST, unregistred user!
1.主窗体代码
TDLLCreateChild =function(app:TApplication;mainForm:TForm):Tform;stdcall ;
var
Form1: TForm1;
Moudle: THandle;
DLLCreateChild:TDLLCreateChild;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
f:TForm;
begin
Moudle := Loadlibrary('testdll.dll');
if Moudle <= 0 then
Application.Terminate;
DLLCreateChild := GetProcAddress(Moudle,'DLLCreateChild');
f:=DLLCreateChild(Application,Application.MainForm);
if f=nil then
exit;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Freelibrary(Moudle);
end;
2.DLL窗体源码
library testdll;
uses
SysUtils, Classes, forms, Messages, Dialogs,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function DLLCreateChild(app:TApplication;mainForm:TForm):Tform;stdcall
var
Form1: TForm1;
I:integer;
ptrLongInt;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
for i:=app.MainForm.MDIChildCount-1 downto 0 do
begin
ShowMessage(app.MainForm.MDIChildren.Name);
if app.MainForm.MDIChildren= Form1 then
begin
Result:=nil;
break;
end;
Result:=nil;
end;
Form1:=TForm1.Create(MainForm);
result:=Form1;
end;
exports
DLLCreateChild ;
begin
end.
问题:小弟用if app.MainForm.MDIChildren= Form1 then 为什么从来就没有为真结果,那位大哥帮忙解决下这问题,我的目的主要是控制DLL中的MDI子窗口只能创建一个
TDLLCreateChild =function(app:TApplication;mainForm:TForm):Tform;stdcall ;
var
Form1: TForm1;
Moudle: THandle;
DLLCreateChild:TDLLCreateChild;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
f:TForm;
begin
Moudle := Loadlibrary('testdll.dll');
if Moudle <= 0 then
Application.Terminate;
DLLCreateChild := GetProcAddress(Moudle,'DLLCreateChild');
f:=DLLCreateChild(Application,Application.MainForm);
if f=nil then
exit;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Freelibrary(Moudle);
end;
2.DLL窗体源码
library testdll;
uses
SysUtils, Classes, forms, Messages, Dialogs,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function DLLCreateChild(app:TApplication;mainForm:TForm):Tform;stdcall
var
Form1: TForm1;
I:integer;
ptrLongInt;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
for i:=app.MainForm.MDIChildCount-1 downto 0 do
begin
ShowMessage(app.MainForm.MDIChildren.Name);
if app.MainForm.MDIChildren= Form1 then
begin
Result:=nil;
break;
end;
Result:=nil;
end;
Form1:=TForm1.Create(MainForm);
result:=Form1;
end;
exports
DLLCreateChild ;
begin
end.
问题:小弟用if app.MainForm.MDIChildren= Form1 then 为什么从来就没有为真结果,那位大哥帮忙解决下这问题,我的目的主要是控制DLL中的MDI子窗口只能创建一个