Access Violation Problem in LoadFromFile
I brought up this Access Violation problem more than two years ago (Aug 21,
2006 20:24) when I was using RB 7.04 and received responses from Nico Cizik.
I thought I had a work around, but now I am using RB 10.09 and the same
problem seems to have reappeared. In the older version, my workaround was
setting the RecordCount to -1 after using the JITpipeline. This does not
appear to work in version 10.09.
I am using a report template that uses a JITpipeline and other templates
that do not use the JITpipeline. I normally set the visible property of the
JITpipeline to true if using the report template that uses the JIT, and set
it to false when loading the other templates. The problem happens when I
preview the template that uses the JITpipeline and then preview one of the
other templates that does not use it. The first preview is fine, but when I
preview one of the other templates right afterward, I get an Access
Violation (when calling Template.LoadFromFile). However, note that this
access violation only happens when running the application from the Delphi
IDE. It does not happen in the compiled application. Nevertheless, there
is still a problem because if I preview the JITpipeline template again, then
preview another template, then I get another access violation even when the
application is running as a stand alone app (outside the IDE).
I have traced through the source code and found the problem has something to
do with freeing memory.
{In ppDBPipe.pas}
procedure TppDBPipeline.FreeBookmark(aBookmark: Longint);
begin
{note: use FDataSet here because FDataLink.DataSet returns nil
when the TDataSource or TDataSet objects are csDestroying}
if (FDataSet <> nil) then {<< Violation Occurs Here !!!!!! ***
!!!!!!!!!!!}
FDataSet.FreeBookmark(TBookmark(aBookmark))
else if (FDataLink <> nil) and (FDataLink.DataSet <> nil) then
FDataLink.DataSet.FreeBookmark(TBookmark(aBookmark));
end; {procedure, FreeBookmark}
It seems like maybe FDataSet is not being set to nil after closing the
preview of the template using the JITpipeline. Can you direct me how to
correct this or can you suggest a work around?
David M.
Delphi 2007, RB 10.09, NexusDB 2.0706
===========================
Following outlines a more through trace:
fmRep1.ppRepFormsLetters.Template.LoadFromFile;
{ppTmplat.pas}
procedure TppTemplate.LoadFromFile;
begin
LoadFromSource(stFile);
end; {procedure, LoadFromFile}
procedure TppTemplate.LoadFromSource(aSaveToType: TppSaveToType);
procedure TppTemplate.LoadFromStream(aStream: TStream);
procedure TppReportTemplate.LoadEnd(aLoaded: Boolean);
{ppReport.pas}
procedure TppReport.Transfer(aSource: TppCommunicator);
{ppCache.pas}
procedure TppCacheManager.ResetCache;
begin
FreeStreams; {procedure TppCacheManager.FreeStreams;} {<< Trips Here
!!!!!!!}
CreateStreams;
end; {procedure, ResetCache}
{ppCache.pas}
procedure TppCacheManager.TakeCacheAction(aAction: TppCacheActionType;
aCachePageNo: Longint);
...
procedure TppEngine.FreeCache(aCachePageNo: Integer);
...
lCacheable.FreeCache(aCachePageNo); {<< Trips Here !!!!!!!}
{ppEngine.pas}
procedure TppEngine.FreeBookmarks(aStartPageNo: Integer);
...
lMasterDataPipeline.FreeBookmark(lRec.FMasterBookmark); {<< Trips Here
!!!!!!!}
{ppDBPipe.pas}
procedure TppDBPipeline.FreeBookmark(aBookmark: Longint);
begin
{note: use FDataSet here because FDataLink.DataSet returns nil
when the TDataSource or TDataSet objects are csDestroying}
if (FDataSet <> nil) then {<< Trips Here !!!!!!!}
FDataSet.FreeBookmark(TBookmark(aBookmark))
else if (FDataLink <> nil) and (FDataLink.DataSet <> nil) then
FDataLink.DataSet.FreeBookmark(TBookmark(aBookmark));
end; {procedure, FreeBookmark}
{nxmmItemManager.pas}
function _FreeMem(aPointer: Pointer): Integer;
asm
mov edx, eax
test edx, $0000FFFF
jz _FreeMemLarge
and eax, $FFFF0000
mov eax, dword ptr [eax + TnxMemoryPoolBlockHeader.mpbhMemoryPool]
{<< Trips Here !!!!!!!}
jmp TnxMemoryPool.DisposeDirect
end;
2006 20:24) when I was using RB 7.04 and received responses from Nico Cizik.
I thought I had a work around, but now I am using RB 10.09 and the same
problem seems to have reappeared. In the older version, my workaround was
setting the RecordCount to -1 after using the JITpipeline. This does not
appear to work in version 10.09.
I am using a report template that uses a JITpipeline and other templates
that do not use the JITpipeline. I normally set the visible property of the
JITpipeline to true if using the report template that uses the JIT, and set
it to false when loading the other templates. The problem happens when I
preview the template that uses the JITpipeline and then preview one of the
other templates that does not use it. The first preview is fine, but when I
preview one of the other templates right afterward, I get an Access
Violation (when calling Template.LoadFromFile). However, note that this
access violation only happens when running the application from the Delphi
IDE. It does not happen in the compiled application. Nevertheless, there
is still a problem because if I preview the JITpipeline template again, then
preview another template, then I get another access violation even when the
application is running as a stand alone app (outside the IDE).
I have traced through the source code and found the problem has something to
do with freeing memory.
{In ppDBPipe.pas}
procedure TppDBPipeline.FreeBookmark(aBookmark: Longint);
begin
{note: use FDataSet here because FDataLink.DataSet returns nil
when the TDataSource or TDataSet objects are csDestroying}
if (FDataSet <> nil) then {<< Violation Occurs Here !!!!!! ***
!!!!!!!!!!!}
FDataSet.FreeBookmark(TBookmark(aBookmark))
else if (FDataLink <> nil) and (FDataLink.DataSet <> nil) then
FDataLink.DataSet.FreeBookmark(TBookmark(aBookmark));
end; {procedure, FreeBookmark}
It seems like maybe FDataSet is not being set to nil after closing the
preview of the template using the JITpipeline. Can you direct me how to
correct this or can you suggest a work around?
David M.
Delphi 2007, RB 10.09, NexusDB 2.0706
===========================
Following outlines a more through trace:
fmRep1.ppRepFormsLetters.Template.LoadFromFile;
{ppTmplat.pas}
procedure TppTemplate.LoadFromFile;
begin
LoadFromSource(stFile);
end; {procedure, LoadFromFile}
procedure TppTemplate.LoadFromSource(aSaveToType: TppSaveToType);
procedure TppTemplate.LoadFromStream(aStream: TStream);
procedure TppReportTemplate.LoadEnd(aLoaded: Boolean);
{ppReport.pas}
procedure TppReport.Transfer(aSource: TppCommunicator);
{ppCache.pas}
procedure TppCacheManager.ResetCache;
begin
FreeStreams; {procedure TppCacheManager.FreeStreams;} {<< Trips Here
!!!!!!!}
CreateStreams;
end; {procedure, ResetCache}
{ppCache.pas}
procedure TppCacheManager.TakeCacheAction(aAction: TppCacheActionType;
aCachePageNo: Longint);
...
procedure TppEngine.FreeCache(aCachePageNo: Integer);
...
lCacheable.FreeCache(aCachePageNo); {<< Trips Here !!!!!!!}
{ppEngine.pas}
procedure TppEngine.FreeBookmarks(aStartPageNo: Integer);
...
lMasterDataPipeline.FreeBookmark(lRec.FMasterBookmark); {<< Trips Here
!!!!!!!}
{ppDBPipe.pas}
procedure TppDBPipeline.FreeBookmark(aBookmark: Longint);
begin
{note: use FDataSet here because FDataLink.DataSet returns nil
when the TDataSource or TDataSet objects are csDestroying}
if (FDataSet <> nil) then {<< Trips Here !!!!!!!}
FDataSet.FreeBookmark(TBookmark(aBookmark))
else if (FDataLink <> nil) and (FDataLink.DataSet <> nil) then
FDataLink.DataSet.FreeBookmark(TBookmark(aBookmark));
end; {procedure, FreeBookmark}
{nxmmItemManager.pas}
function _FreeMem(aPointer: Pointer): Integer;
asm
mov edx, eax
test edx, $0000FFFF
jz _FreeMemLarge
and eax, $FFFF0000
mov eax, dword ptr [eax + TnxMemoryPoolBlockHeader.mpbhMemoryPool]
{<< Trips Here !!!!!!!}
jmp TnxMemoryPool.DisposeDirect
end;
This discussion has been closed.
Comments
This is being researched. Will post a follow up here.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Prior to loading the report template, call Report.DumpCache.
Example:
ppReport1.DumpCache;
ppReport1.Template.FileName := 'c:\TestReport.rtm';
ppReport1.Template.LoadFromFile;
ppReport1.Print;
For RB 11, a fix will be implemented for the next maintenance release, so
that the above call is not necessary.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
I use RB10.09 for Delphi 7 in windows XP.
Some times when I load old RB Template show error Access Violation if I
use prior to loading the report template, call Report.DumpCache then
fixed my problem?
Regards,
Ali Abbasi
so
Best regards,
Ali Abbasi
--- posted by geoForum on http://delphi.newswhat.com
have found this without your help. Thank you very much.
David Miller.
Give it a try, perhaps you have a similar issue.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com