setting a report backpicture from code?

hsmhsm
edited 12:52PM in FastReport 4.0
I'm allowing users to pick a report background picture , plus other static pictures and text, and via a setup screen that stores the paths/text inside Pascal variables and a database. When my Pascal program starts I try to set the backpicture and other pictures of the report so its ready when opened, but am getting an access violation when I try to refer to the page. I get the error on the first line so it seem it can't find pages[1].

Am I doing this right?

(I have Uses frxClass, U_100PctCertificate; in the module, U_100PctCertificate contains the formFrmCertificates which contains the report frxReportCertificate. )

The code I have is as follows

Howard
procedure TFrmConstantsAndPreferences.LoadPicturesAndTextIntoCertificate;
var
CertificatePicture : TfrxPictureView;
CertificatePage : TfrxReportPage;
CertificateText : TfrxMemoView;
begin


 CertificatePage := FrmCertificates.frxReportCertificate.Pages[1] as TfrxReportPage;  //point to the certificate page
 CertificatePage.BackPicture.LoadFromFile(GetCertBackgroundPath); //load background picture

 CertificatePicture  := FrmCertificates.frxReportCertificate.FindObject('ImageLogo') as TfrxPictureView;   //point to the logo
 CertificatePicture.Picture.LoadFromFile(GetLogoPath); //load the image into it

 CertificatePicture  := FrmCertificates.frxReportCertificate.FindObject('ImageSignature') as TfrxPictureView;   //point to the signature
 CertificatePicture.Picture.LoadFromFile(GetSignaturePath); //load the image into it

 CertificateText   := FrmCertificates.frxReportCertificate.FindObject('MemoSchoolName') as TfrxMemoView;   //point to the institution name
 CertificateText.Memo.Clear;
 CertificateText.Memo.Add(GetInstitutionName);

 CertificateText   := FrmCertificates.frxReportCertificate.FindObject('MemoSigTitle') as TfrxMemoView;   //point to the signatory title
 CertificateText.Memo.Clear;
 CertificateText.Memo.Add(GetSignatoryTitle);
end;

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 12:52PM
    have you loaded the report into the tfrxcomponent first
  • hsmhsm
    edited January 2011
    gordk wrote: »
    have you loaded the report into the tfrxcomponent first

    I'm not sure what you mean by loading the report into the trfxcomponent.
    All the code I have is what I showed. I haven't saved the report to a file or anything, just have the component (and associoated datasets etc) sitting on a form.

    Please could you show me what I need to write to load it?

    BTW The report works fine when I load the graphics and text in the 'code' section of the report.
    I was trying to save time by having it already there when the report is opened.

    Howard
  • gordkgordk St.Catherines On. Canada.
    edited 12:52PM
    since you are not saving the report to file you won't be loading it.
    typical call to access the report page from the programmers manual.
    var Page: tfrxreportpage;
    Page := TfrxReportPage(frxReport1.Pages[1]);
    your code
    CertificatePage := FrmCertificates.frxReportCertificate.Pages[1] as TfrxReportPage;
    should probably be
    CertificatePage := (FrmCertificates.frxReportCertificate.Pages[1]);

    CertificatePage.backpicture.loadfromfile('path&filename');
    make sure you also set visible and printable props of backpicture to suit.


  • hsmhsm
    edited 12:52PM
    Thanks Gordk but your suggestion to use
    CertificatePage := (FrmCertificates.frxReportCertificate.Pages[1]);
    first of all gave me an 'incompatible type TfrxReportPage and TfrxPage'.
    When I changed the data type of Certificate page from TfrxReportPage to TfrxPage the compiler is happy with that line but then says that backpicture is an unknown identifier in the next line, CertificatePage.backpicture.loadfromfile('path&filename'), This would seem to make sense as backpicture is a method of a TfrxReportPage object but not of a TfrxPage object.

    I think you might have meant to cast it to a TfrxReportPage first like this
    CertificatePage := TfrxReportPage(FrmCertificates.frxReportCertificate.Pages[1])
    that compiles but still gives the access violation error on that line.

    I was following the example from page 9 of the programmers manual with the small exception that the example appears to assume the code is running in the same form as the report as the variable 'frxReport1' is not further qualified. I thought that by qualifying it with the name of the form containing it (FrmCertificates in my case) that it would work. Indeed, my original code compiled ok but then got the run time error.

    I must be close, any other ideas?
    Howard
  • gordkgordk St.Catherines On. Canada.
    edited 12:52PM
    you answered your own question you should be in the same form as the tfrxreport component.
    or you must store reports in a file and call load report from file method or stream etc.
    typical
    myform.frxreport1.loadfromfile('pathandfilename.fr3'); // now you have a report loaded
    into a report component and you can access the pages objects etc.
    then call show report.
    remeber the called form must be availabe to the calling form.
  • hsmhsm
    edited 12:52PM
    gordk wrote: »
    you answered your own question you should be in the same form as the tfrxreport component.
    or you must store reports in a file and call load report from file method or stream etc.
    typical
    myform.frxreport1.loadfromfile('pathandfilename.fr3'); // now you have a report loaded
    into a report component and you can access the pages objects etc.
    then call show report.
    remeber the called form must be availabe to the calling form.

    OK Thanks Gordk, In frustration I did move it back to the original form and loaded the pictures in the OBP moethod where I knew it worked previously and now its OK. Yours is a tip worth remembering though.
    I'll keep the report in the form as I don't want to have to distibute .fr3 files as well with my application.
    Regards
    Howard

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.