Dll窗体重用

//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 = 0then
            FreeLibrary(LibHandle);
    
end else
        CanClose :
= False;
end;

关键是无论DLL还是EXE都要带运行时间包VCL50.bpl编译 
 
这是一个调用DLL中MDICHILDFORM的例子,改成其他窗体类型,一样能用
posted @ 2008-07-29 08:38  威尼斯的夏天  阅读(208)  评论(0编辑  收藏  举报