//DLL library Func;uses ShareMem, SysUtils, Classes, Forms, Windows, MConnect, Child2 in 'Child2.pas' {FormChild2};{$R *.RES}procedure CallModule();stdcall;export; begin if not Assigned(FormChild2) then FormChild2 := TFormChild2.Create(Application); FormChild2.Show; end;exports CallModule;begin end;//MDIChild单元:procedure TFormChild2.N9Click(Sender: TObject); begin Close; end;procedure TFormChild2.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end;procedure TFormChild2.FormDestroy(Sender: TObject); begin FormChild2 := nil; end;
//主程序: type TCallModule = procedure();stdcall;var FormMain: TFormMain; LibHandle: HModule; procedure LoadModule(AModuleName: String);implementation{$R *.DFM} procedure LoadModule(AModuleName: String); var CallModule: TCallModule; begin LibHandle := LoadLibrary(PChar(AModuleName)); if LibHandle = 0 then Exit; @CallModule := GetProcAddress(LibHandle,'CallModule'); if @CallModule <> nil then CallModule(); end;procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var iCount: Integer; begin if MessageDLG('是否退出?',mtConfirmation,[mbYes,mbNO],0) = mrYes then begin for iCount := 0 to MDIChildCount - 1 do MDIChildren[iCount].Close; CanClose := True; if not (LibHandle = 0) then FreeLibrary(LibHandle); end else CanClose := False; end;关键是无论DLL还是EXE都要带运行时间包VCL50.bpl编译
library Func;uses
ShareMem,
SysUtils,
Classes,
Forms,
Windows,
MConnect,
Child2 in 'Child2.pas' {FormChild2};{$R *.RES}procedure CallModule();stdcall;export;
begin
if not Assigned(FormChild2) then
FormChild2 := TFormChild2.Create(Application);
FormChild2.Show;
end;exports
CallModule;begin
end;//MDIChild单元:procedure TFormChild2.N9Click(Sender: TObject);
begin
Close;
end;procedure TFormChild2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;procedure TFormChild2.FormDestroy(Sender: TObject);
begin
FormChild2 := nil;
end;
//主程序:
type
TCallModule = procedure();stdcall;var
FormMain: TFormMain;
LibHandle: HModule;
procedure LoadModule(AModuleName: String);implementation{$R *.DFM}
procedure LoadModule(AModuleName: String);
var
CallModule: TCallModule;
begin
LibHandle := LoadLibrary(PChar(AModuleName));
if LibHandle = 0 then Exit;
@CallModule := GetProcAddress(LibHandle,'CallModule');
if @CallModule <> nil then
CallModule();
end;procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
iCount: Integer;
begin
if MessageDLG('是否退出?',mtConfirmation,[mbYes,mbNO],0) = mrYes then
begin
for iCount := 0 to MDIChildCount - 1 do
MDIChildren[iCount].Close;
CanClose := True;
if not (LibHandle = 0) then
FreeLibrary(LibHandle);
end else
CanClose := False;
end;关键是无论DLL还是EXE都要带运行时间包VCL50.bpl编译
你还可以到下列帖子去看看,其实这类帖子太多啦,你应该搜索先,今天这是第三帖啦:http://www.csdn.net/expert/topic/535/535779.xml?temp=.2144892
http://www.csdn.net/expert/topic/634/634413.xml?temp=.5008661