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

LoadFromFile procedure gives me file can't open using ppRichtText Component

edited September 2004 in Devices
LoadFromFile procedure gives me file can't open using ppRichtText Component.
I have a ppRichText component on a ppReport. When I try to programmactialy
change the file for the ppRichText, using the LoadFromFile proceudre I get
the following:
1)If using a filename with the extentsion (c:\mydocuments\test.rtf) then
I get AV errors
2)If I use a filename without the extension (c:\mydocuements\test) I
then get File cannot open error.
Is there something wrong with that procedure or I am doing something wrong?
I am using Delphi 6, Report Builder Enterprise Edition 7.03

Thanks for your time

Comments

  • edited September 2004
    Hi Semone,

    Are you able to load this file into a TppRichText component from the
    designer successfully? The RichText in ReportBuilder is a wrapper around
    Delphi's TRichEdit which in turn relies on Windows. Try loading your file
    into a TRichEdit component on a form and see if that works correctly. When
    are you trying to load the rich text file? In my testing, with RB 7.04,
    loading a simple Test.rtf file from code worked as expected.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    1. Yes I am able to load this file (.rtf) successfully in the tppRichText
    component from the design level

    2. Loading that file into a TRichEdit on a form does fine. And I am using
    the LoadFromFile procedure.

    3. I am loading it before I print the report, here is the sample code:
    DataSource1.DataSet := Qry;
    BdayLetter.Template.FileName := BirthdayReport_file;
    BdayLetter.Template.Load;
    ppImage1.Picture.LoadFromFile(BirthdayPic);
    birthdayletter.LoadFromFile(letterfile);
    Bdayletter.DeviceType := 'Screen';
    Bdayletter.Print;

    **the letterfile is the .rtf file

  • edited September 2004
    Semone,

    When you load a template, the objects that are currently on the report no
    longer exist, therefore the reason you are receiving an AV is that the
    birthdayletter TppRichText component does not exist any more. The image is
    working correctly because you are simply getting lucky with the name in the
    original report matching the name in the template :). I would recommend
    fixing this in both cases so you do not run into similar problems in the
    future and have a more solid application. Instead of loading the image and
    .rtf file directly from a named object, try creating an object loop and find
    the proper objects in your report and assign the files that way. Something
    like the following...

    var
    liBand: Integer;
    liObject: Integer;
    lObject: TppComponent;
    begin

    BdayLetter.Template.FileName := BirthdayReport_file;
    BdayLetter.Template.Load;

    for liBand := 0 to BdayLetter.BandCount-1 do

    for liObject := 0 to BdayLetter.Bands[liBand].ObjectCount-1 do
    begin
    lObject := BdayLetter.Bands[liBand].Objects[liObject];

    if lObject is TppImage then
    TppImage(lObject).Picture.LoadFromFile(BirthdayPic);

    if lObject is TppRichText then
    TppRichText(lObject).LoadFromFile(letterfile);

    end;
    end;

    BdayLetter.Print;
    end;



    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    Thanks Nico, I will give that a try. But I am not getting AV's if I don't
    put the file extension. I get can't open document error. If that makes any
    difference

  • edited September 2004
    Nico, I tried the code you gave me and got the same thing. Can't open the
    document, the field that I am using.
    Anymore suggestions?

  • edited September 2004
    Semone,

    You are not receiving an AV because ReportBuilder is throwing an exception
    letting you know the file defined does not exist before the AV occurs. If
    RB did not check for a valid file name you would still see an AV.

    --
    Best Regards,

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

    You need to include the entire path name and file name when loading files
    into Delphi objects. Below is a simple example implementing the code I gave
    in a previous post.

    http://www.digital-metaphors.com/tips/TemplateLoadRichText.zip

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2004
    Thanks soo much Nico for working and being patient with me. Thanks. And it
    worked by the way.
This discussion has been closed.