新
新来的菜鸟
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我调用dll子窗体的函数,每次主窗体调用完dll后关闭主窗体就会出错!我想应该是没有释放子窗体的缘故,应该如何释放子窗体呢?请高手告知谢谢!
调用字窗体
function TForm1.Dllfrmshow(frm:integer;dllname:string):boolean;
type
Windowmax= function :boolean;stdcall;
openform =function (pbase:basemsg):string;
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;
Tf:Windowmax;
Tf2penform;
Tp,Tp2:TFarProc;
begin
if DllHandle_rk[frm] = 0 then
begin
DllHandle_rk[frm] :=LoadLibrary(PChar(extractfilepath(application.ExeName)+'dll/'+dllname));
if DllHandle_rk[frm] = 0 then
begin
showmessage('调入失败!');
exit;
end;
Windowsid:=frm;
//////////////////////载入函数
//////////////////////载入函数
//DllHandle_rk[frm]:= DLLHandle;
try
if DllHandle_rk[frm] <> 0 then
begin
@DLLSub := GetProcAddress(DllHandle_rk[frm], 'CreateDLLForm');
if Assigned(DLLSub) then
DLLForm := DLLSub(Application, Screen);
////////////////////传递pbase类给dll
Tp2:=GetProcAddress(DllHandle_rk[frm],PChar('openform')); /////open dll函数
Pbase.userid :='yzl';
Pbase.phandle:=Handle;
Pbase.Windowsid:=frm;
if Tp2<>nil
then
begin
Tf2:=openform(Tp2);
BitBtn_Competence[frm]:=Tf2(pbase);
end;
////////////////////传递pbase类给dll
BitBtn_Control(BitBtn_Competence[frm]); ///////初始按钮权限
end;
except
FreeLibrary(DllHandle_rk[frm]);
end;
end
else
begin
BitBtn_Control(BitBtn_Competence[frm]);
Windowsid:=frm;
Tp:=GetProcAddress(DllHandle_rk[frm],PChar('Windowmax')); ////窗口最大化函数
if Tp<>nil
then
begin
Tf:=Windowmax(Tp);
Tf();
end;
end;
end;
主窗体关闭是进行释放,但还是出错我定义了一个 DllHandle_rk:array[0..150] of Thandle;//DLL文件存放入口 用于存放DLL的Handle的,不知释放的对否,请高手解答谢谢
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i:integer;
begin
for i:=1 to 10 do
if DllHandle_rk <> 0 then
FreeLibrary(DllHandle_rk);
self.Close;
end;
调用字窗体
function TForm1.Dllfrmshow(frm:integer;dllname:string):boolean;
type
Windowmax= function :boolean;stdcall;
openform =function (pbase:basemsg):string;
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;
Tf:Windowmax;
Tf2penform;
Tp,Tp2:TFarProc;
begin
if DllHandle_rk[frm] = 0 then
begin
DllHandle_rk[frm] :=LoadLibrary(PChar(extractfilepath(application.ExeName)+'dll/'+dllname));
if DllHandle_rk[frm] = 0 then
begin
showmessage('调入失败!');
exit;
end;
Windowsid:=frm;
//////////////////////载入函数
//////////////////////载入函数
//DllHandle_rk[frm]:= DLLHandle;
try
if DllHandle_rk[frm] <> 0 then
begin
@DLLSub := GetProcAddress(DllHandle_rk[frm], 'CreateDLLForm');
if Assigned(DLLSub) then
DLLForm := DLLSub(Application, Screen);
////////////////////传递pbase类给dll
Tp2:=GetProcAddress(DllHandle_rk[frm],PChar('openform')); /////open dll函数
Pbase.userid :='yzl';
Pbase.phandle:=Handle;
Pbase.Windowsid:=frm;
if Tp2<>nil
then
begin
Tf2:=openform(Tp2);
BitBtn_Competence[frm]:=Tf2(pbase);
end;
////////////////////传递pbase类给dll
BitBtn_Control(BitBtn_Competence[frm]); ///////初始按钮权限
end;
except
FreeLibrary(DllHandle_rk[frm]);
end;
end
else
begin
BitBtn_Control(BitBtn_Competence[frm]);
Windowsid:=frm;
Tp:=GetProcAddress(DllHandle_rk[frm],PChar('Windowmax')); ////窗口最大化函数
if Tp<>nil
then
begin
Tf:=Windowmax(Tp);
Tf();
end;
end;
end;
主窗体关闭是进行释放,但还是出错我定义了一个 DllHandle_rk:array[0..150] of Thandle;//DLL文件存放入口 用于存放DLL的Handle的,不知释放的对否,请高手解答谢谢
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i:integer;
begin
for i:=1 to 10 do
if DllHandle_rk <> 0 then
FreeLibrary(DllHandle_rk);
self.Close;
end;