主窗体调用函数 function functionDetect(libName,funcName:string;var libPointer:pointer):boolean; var libHandle:THandle; begin result:=false; libPointer:=nil; if LoadLibrary(PChar(libName))=0 then exit; libhandle:=GetModuleHandle(PChar(libName)); if libHandle<>0 then begin libPointer:=GetProcAddress(libHandle,PChar(funcName)); if libPointer<>nil then result:=true; end end;
procedure loadModule(moduleFile:string); var pShowForm:function(hHandle:HWND;conn:TADOConnection):bool;stdcall; mFile:string; begin mFile:=ExtractFilePath(ParamStr(0))+'Lib\'+moduleFile; if functionDetect(mFile,'showForm',@pShowForm) then pShowForm(Application.Handle,DM.connMain) else Application.MessageBox('没有找到此模块!请核对!','错误',MB_ICONERROR+MB_OK); end;
DLL函数声明 function showForm(hHandle:HWND;conn:TADOConnection):boolean;stdcall; //记得要导出哦 ! var f:TfrmTokenAttri; begin result:=false; PUB_CONN:=conn; //PUB_CONN为全局数据库连接变量,用于控制整个模块联结,外部定义 Application.Handle:=hHandle; try f:=TfrmTokenAttri.Create(nil); f.ShowModal; result:=true; finally f.Free; end; end;