LoadFromFile procedure gives me file can't open using ppRichtText Component
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
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
This discussion has been closed.
Comments
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.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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
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;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
put the file extension. I get can't open document error. If that makes any
difference
document, the field that I am using.
Anymore suggestions?
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.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
worked by the way.