我写了一个Dll,在应用程序中调用没有发现什么问题
但是我在调试的时候却出现如下情况:(我的Dll中有窗体)我在每次关闭主调用程序时都会弹出CPU View框,我必须在Delphi IDE环境中手动关闭,才可以,这种情况的出现我估计是因为我资源销毁的问题导致了内存泄漏。不知是否这样?有什么办法能解决呢?或者说用什么方法能检测出是什么地方导致了内存泄漏呢?有工具可以检测吗?
但是我在调试的时候却出现如下情况:(我的Dll中有窗体)我在每次关闭主调用程序时都会弹出CPU View框,我必须在Delphi IDE环境中手动关闭,才可以,这种情况的出现我估计是因为我资源销毁的问题导致了内存泄漏。不知是否这样?有什么办法能解决呢?或者说用什么方法能检测出是什么地方导致了内存泄漏呢?有工具可以检测吗?
var
frmSearch: TfSearch;
theDb: TmyDM;
begin
theDb := TMyDM.Create(nil);
if not theDb.OpenDb(0) then
begin
Result := -1; //操作失败,数据库打开失败
Exit;
end;
try
frmSearch := TfSearch.Create(theDb);
frmSearch.ShowModal;
Result := theDb.resRows;
frmSearch.Free;
except
Result := -1;
end;
theDb.Free;
end;
并尽可能修正为:if assigned(x) then begin
x.Free;
x := nil;
end;(注:ShowModal 对Handle没有特殊要求)
代码如下,请指出问题在什么地方?function SearchAll(H: THandle;intFunc: Integer;var intOperType: Integer;var strKeyWords: PChar): Integer;stdcall;
var
theDb: TmyDM;
fRes: TfResult;
fHit: TfrmSearching;
begin
Application.Handle := H; theDb := TMyDM.Create(nil);
if not theDb.OpenDb(0) then
begin
Result := -1; //操作失败,数据库打开失败
Exit;
end;
theDb.theFunc := intFunc; //将调用的功能号存入DbLib单元 theDb.GetFuncInfo(theDb.theFunc);
theDb.strSearchSql := theDb.GetSqlString;
try
fHit := TfrmSearching.Create(theDb);
try
fHit.ShowModal;
finally
fHit.Free;
end; ////////////////// 结束检索 /////////////////
if theDb.resRows <= 0 then
begin
Application.MessageBox('对不起,没有检索到满足条件的记录!','提示',MB_OK + MB_ICONINFORMATION);
Result := 0;
end
else
begin
fRes := TfResult.Create(theDb);
try
fRes.ShowModal;
Result := theDb.resRows;
intOperType := fRes.resOperType; //获得操作类型
strKeyWords := PChar(fRes.resKeyWords); //获得关键字值
finally
fRes.Free;
end;
end; finally
theDb.Free;
end;
end;