Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Access violation when call TppReport.Template.New repeatedly

edited August 2004 in General
Hi,

I encounter an access violation in Report Builder 7.04 when perform
TppReport.Template.New repeatedly. This error has trouble me for quite
some time and now I am able to write a simple test case to show how to
replay access violation:

1. Create a simple report template that contains a subreport with a
variable reside in the subreport, write a simple code for the variable.
Then save the report to a text file named "c:\sample.rtm".

object ppReport1: TppReport
PrinterSetup.BinName = 'Default'
PrinterSetup.DocumentName = 'Report'
PrinterSetup.PaperName = 'Letter (8.5 x 11 in.)'
PrinterSetup.PrinterName = 'Default'
PrinterSetup.mmMarginBottom = 6350
PrinterSetup.mmMarginLeft = 6350
PrinterSetup.mmMarginRight = 6350
PrinterSetup.mmMarginTop = 6350
PrinterSetup.mmPaperHeight = 279401
PrinterSetup.mmPaperWidth = 215900
PrinterSetup.PaperSize = 1
Template.FileName = 'C:\sample1.rtm'
Template.Format = ftASCII
DeviceType = 'Screen'
OutlineSettings.CreateNode = True
OutlineSettings.CreatePageNodes = True
OutlineSettings.Enabled = True
OutlineSettings.Visible = True
TextSearchSettings.DefaultString = ''
TextSearchSettings.Enabled = True
Left = 122
Top = 38
Version = '7.04'
mmColumnWidth = 0
object ppHeaderBand1: TppHeaderBand
mmBottomOffset = 0
mmHeight = 8731
mmPrintPosition = 0
end
object ppDetailBand1: TppDetailBand
PrintHeight = phDynamic
mmBottomOffset = 0
mmHeight = 11377
mmPrintPosition = 0
object ppSubReport1: TppSubReport
UserName = 'SubReport1'
ExpandAll = False
NewPrintJob = False
OutlineSettings.CreateNode = True
TraverseAllData = False
mmHeight = 5027
mmLeft = 0
mmTop = 2646
mmWidth = 203200
BandType = 4
mmBottomOffset = 0
mmOverFlowOffset = 0
mmStopPosition = 0
object ppChildReport1: TppChildReport
PrinterSetup.BinName = 'Default'
PrinterSetup.DocumentName = 'Report'
PrinterSetup.PaperName = 'Letter (8.5 x 11 in.)'
PrinterSetup.PrinterName = 'Default'
PrinterSetup.mmMarginBottom = 6350
PrinterSetup.mmMarginLeft = 6350
PrinterSetup.mmMarginRight = 6350
PrinterSetup.mmMarginTop = 6350
PrinterSetup.mmPaperHeight = 279401
PrinterSetup.mmPaperWidth = 215900
PrinterSetup.PaperSize = 1
Template.Format = ftASCII
Version = '7.04'
mmColumnWidth = 0
object ppTitleBand1: TppTitleBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
end
object ppDetailBand2: TppDetailBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
object ppVariable2: TppVariable
UserName = 'Variable2'
CalcOrder = 0
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Name = 'Arial'
Font.Size = 10
Font.Style = []
Transparent = True
mmHeight = 3969
mmLeft = 3704
mmTop = 4233
mmWidth = 14817
BandType = 4
end
end
object ppSummaryBand1: TppSummaryBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
end
object raCodeModule2: TraCodeModule
ProgramStream = {

01060F5472614576656E7448616E646C65720B50726F6772616D4E616D65060F

5661726961626C65324F6E43616C630B50726F6772616D54797065070B747450

726F63656475726506536F75726365065570726F636564757265205661726961

626C65324F6E43616C63287661722056616C75653A2056617269616E74293B0D

0A626567696E0D0A0D0A202056616C7565203A3D202754657374273B0D0A0D0A

656E643B0D0A0D436F6D706F6E656E744E616D6506095661726961626C653209
4576656E744E616D6506064F6E43616C63074576656E74494402210000}
end
end
end
end
object ppFooterBand1: TppFooterBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
end
object raCodeModule1: TraCodeModule
ProgramStream = {00}
end
end




2. Use Delphi to run the following code:

procedure TForm1.GetGroupInfo(AStr: string; var GroupByOf:
string; var GroupingLevel: Integer);
var I: Integer;
lStrStream: TStringStream;
begin
lStrStream := TStringStream.Create(AStr);
try
GroupByOf := '';
ppReport1.Template.New;
ppReport1.Template.LoadFromStream(lStrStream);
GroupingLevel := ppReport1.GroupCount;
for I := 0 to GroupingLevel - 1 do
if GroupByOf = '' then
GroupByOf := ppReport1.Groups[I].BreakName
else
GroupByOf := GroupByOf + ';' + ppReport1.Groups[I].BreakName;
finally
lStrStream.Free;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var S: TStringList;
groupbyof: string;
i: integer;
j: integer;
begin
S := TStringList.Create;
try
for j := 1 to 10000 do begin
S.LoadFromFile('c:\sample.rtm');
GetGroupInfo(S.Text, groupbyof, i);
end;
finally
S.Free;
end;
ShowMessage('No Error');
end;


3. You will notice the Button1Click event won't prompt 'No error'.
Instead Access Violation will prompt in the for loop. I notice the
access violation occurs at ppReport1.Template.New.

4. After perform more debugging. I found the access violation occurs at
ppComm.pas lines 606:

procedure TppCommunicator.Notify(aCommunicator: TppCommunicator;
aOperation: TppOperationType);
var
liIndex: Integer;
begin

if Assigned(FOnNotify) then FOnNotify(Self, aCommunicator, aOperation);


if (aOperation <> ppopRemove) then Exit;

if (FNotifyList <> nil) then <========== AV occurs here.
....
end;

Best regards,
Yang

Comments

  • edited August 2004
    Hi Yang,

    Thanks for the example. I was able to recreate the error and am currently
    looking into the cause of the problem. I'll let you know when I find
    something. Thanks for your patience.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2004
    Hi Nico,

    Thank you very much. I think this could be the reason that some users
    report that they encounter AV on and off but unable to reproduce the
    problem.

    I suspect the AV occurs only when there are script written on the
    report. The script engine might be the cause of the problem.

  • edited August 2004
    Hi Yang,

    There is now a patch available for ReportBuilder 7.04 that addresses this
    issue. Please send an email requesting this patch to
    support@digital-metaphors.com and we'll send it to you asap.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    I have found the following solutions to overcome the problem:

    Call the following procedure before call ppReport1.Template.New or
    ppReport1.Template.LoadFromFile or ppReport1.Template.LoadFromStream.

    procedure ResetReport(AReport: TppCustomReport);
    var lCodeModule: TComponent;
    i: integer;
    S: TStringList;
    begin
    // BUG: Report Builder may sometime prompt Access Violation if TppReport
    instance
    // has been loaded with report that contain script. The following code
    // will perform clean up task.
    lCodeModule := AReport.CodeModule;
    FreeAndNil(lCodeModule);

    S := TStringList.Create;
    try
    AReport.GetSubReports(S);
    for i := S.Count - 1 downto 0 do begin
    lCodeModule := TppChildReport(S.Objects[i]).CodeModule;
    FreeAndNil(lCodeModule);
    end;
    finally
    S.Free;
    end;
    end;


This discussion has been closed.