你参考这点代码,是帮别人测试的测试代码,和你的说法相同。
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
LongInt;
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
Array;
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.
-----------------
有的你不需要,你自己删除就好。