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

Offset and Access Violation

edited May 2013 in General
Hi,
I'm trying to use template's offset to store some additional information.
On new reports there is not problem.
However, if I try to modifiy existing report (without offset) I get an
"Access Violation".
I'm using Delphi XE2 (Update 4 Hotfix 1) and ReportBuilder 14.08.
This is the code used:

{ Note: Use compiler directive to declare strings as 'ShortStrings';
This is required for record structures }
{$H-}
{ Record structure used to store informations inside report template }
TT3ReportTemplateInfo = record
HeaderID: Integer;
Comments: String;
end;
{$H+}

////////////////////////////////////////////////////////////////////////////////
procedure TT3ReportProfile.Load;
////////////////////////////////////////////////////////////////////////////////
begin
if FileExists( FFileName ) then begin
FReport.Template.Format := ftBinary;
FReport.Template.Offset := SizeOf( TT3ReportTemplateInfo );
FReport.Template.OnLoadStart := TemplateLoadStart;
FReport.Template.OnSaveEnd := TemplateSaveEnd;
FReport.Template.FileName := FFileName;
FReport.Template.LoadFromFile;
end;
end;

////////////////////////////////////////////////////////////////////////////////
procedure TT3ReportProfile.TemplateLoadStart(Sender: TObject; Stream:
TStream);
////////////////////////////////////////////////////////////////////////////////
var
MyTemplateInfo: TT3ReportTemplateInfo;

begin
Stream.Seek( 0, soFromBeginning );
Stream.Read( MyTemplateInfo, SizeOf( TT3ReportTemplateInfo ) );

if MyTemplateInfo.HeaderID = TEMPLATE_HEADER_ID then
ShowMessage( MyTemplateInfo.Comments )
else begin
FReport.Template.Offset := 0;
end;
end;

////////////////////////////////////////////////////////////////////////////////
procedure TT3ReportProfile.TemplateSaveEnd(Sender: TObject; Stream:
TStream);
////////////////////////////////////////////////////////////////////////////////
var
MyTemplateInfo: TT3ReportTemplateInfo;

begin
MyTemplateInfo.HeaderID := TEMPLATE_HEADER_ID;
MyTemplateInfo.Comments := 'PROVA COMMENTO';

Stream.Seek( 0, soFromBeginning );
Stream.Write( MyTemplateInfo, SizeOf( TT3ReportTemplateInfo ) );
end;

The "Access violation" occurs at end of TemplateLoadStart.

Please help me to solve this problem.

Best regards.
Daniele Buttarelli

Comments

  • edited May 2013
    Hi Daniele,

    Does this occur with every old template? Which version of ReportBuilder
    were these templates created with? If you set your library path to
    RBuilder\Source and trace to where the AV occurs where in the RB code is
    the problem happening?

    As a test, try loading one of the original templates (no offset data)
    using RB 14.08 and re-saving it so it updates, then perform the steps
    below to add info to the template offset.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2013
    This is a multi-part message in MIME format.
  • edited May 2013
    Hi Daniele,

    I apologize, I was under the impression that you had this working for an
    earlier version of ReportBuilder and now it was not functioning after
    upgrading to RB 14.

    Looking at your code, it appears you are first setting the template
    properties and events, then loading a saved template. This will in
    effect overwrite the properties and events that you just set. If you
    are loading templates, you will need to do so before setting any
    properties or events. It may also be necessary to set the Template
    format to ASCII.

    begin
    if FileExists( FFileName ) then begin
    FReport.Template.FileName := FFileName; //Load the template file
    before setting template properties.
    FReport.Template.LoadFromFile;

    FReport.Template.Format := ftASCII;
    FReport.Template.Offset := SizeOf( TT3ReportTemplateInfo );
    FReport.Template.OnLoadStart := TemplateLoadStart;
    FReport.Template.OnSaveEnd := TemplateSaveEnd;
    end;
    end;

    http://www.digital-metaphors.com/rbWiki/Design/Templates/How_To...Store_Information_With_My_Report_Template

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.