怎么在DLL里生成一个MDI Child form?(200分)

  • 主题发起人 主题发起人 mally
  • 开始时间 开始时间
M

mally

Unregistered / Unconfirmed
GUEST, unregistred user!
程序的main form 是一个MDI form,我想在DLL里生成一个main form的MDI Child form。不知道这个能不能实现?我试了一下,直接把DLL里面的form的form style 改成mdi child 是不行的。
 
你参考这点代码,是帮别人测试的测试代码,和你的说法相同。
dll
-----------------------
unit FormDLL;

interface

uses
SysUtils,Windows,Messages,Classes,Graphics,Controls,
Forms,Dialogs,StdCtrls, frxDesgn, frxClass, ADODB, DB; //,frxDBSet,frxClass;

type
TfrmDLL=class(TForm)
btnBioLifePrintPreview:TButton;
frxReport1: TfrxReport;
frxDesigner1: TfrxDesigner;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOQuery1: TADOQuery;
ADOCommand1: TADOCommand;
procedure btnBioLifePrintPreviewClick(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

function ShowForm(mainform:TForm;mybt:TButton):TForm; StdCall;
procedure FormClose(AFormRef:tform); StdCall;

implementation

{$R *.DFM}

{------------------------------------------------------------------------}
function ShowForm(mainForm:TForm;mybt:TButton):TForm;stdcall
var
Form1: TfrmDLL;
ptr:PLongInt;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
Form1:=TfrmDLL.Create(mainForm);
Form1.Show;// .Show;
result:=Form1;
end;

procedure TfrmDLL.btnBioLifePrintPreviewClick(Sender:TObject);
begin
frxReport1.ShowReport;
end;

procedure FormClose(AFormRef:tform);
begin
AFormRef.Release;
end;
---------------
callDll
-------------------------------------
unit TestDLL;

interface

uses
SysUtils,Windows,Messages,Classes,Graphics,Controls,
Forms,Dialogs,StdCtrls,DB,ExtCtrls,DBTables;

type
TShowForm=function(mainform:Tform;mybt:TButton):Tform; StdCall;
tdllFormClose=procedure(tt:Tform); StdCall;

EDLLLoadError=class(Exception);

TfrmCallDLL=class(Tform)
Database1:TDatabase;
btnCallDLL:TButton;
btnClose:TButton;
procedure btnCallDLLClick(Sender:TObject);
end;

var
frmCallDLL:TfrmCallDLL;
type
PArray=^TArray;
TArray=array[0..199] of array[0..199] of TGroupBox;
var
GBox_var:PArray;
mybt:TButton;
implementation
var
LibHandle:THandle;
ShowForm:TShowForm;
dllFormClose:tdllFormClose;
dllform:Tform;
{$R *.DFM}

procedure TfrmCallDLL.btnCallDLLClick(Sender:TObject);
begin
LibHandle:=LoadLibrary('RptDLL.DLL');
try
if LibHandle=HINSTANCE_ERROR then
raise EDLLLoadError.Create('Unable to Load DLL');
@ShowForm:=GetProcAddress(LibHandle,'ShowForm');
@dllFormClose:=GetProcAddress(LibHandle,'FormClose');
if not(@ShowForm=nil) then dllform:=ShowForm(frmCallDLL,mybt);
except
;
end;
end;

end.

-----------------
有的你不需要,你自己删除就好。
 
谢谢。接受答案了。
 
后退
顶部