FR2.53 and LoadFromFile func.
Hi to all
I'm trying to import a jpg image from a directory using BeforePrint.
Procecedure sounds :
procedure TStmpTab.StTabBeforePrint(Memo: TStringList; View: TfrView);
var cStr: string;
begin
if View.Name = 'Picture1' then
begin
cStr := Trim(DM.cPath + 'Scanner\' + IntToStr(DM.ArcScaL.FieldByName ('NroCip').AsInteger) +
DM.ArcScaL.FieldByName('NroDoc').AsString + '.jpg');
if FileExists(cStr) then
(StTab.FindObject('Picture1') as TfrPictureView).Picture.LoadFromFile(cStr)
else
(StTab.FindObject('Picture1') as TfrpictureView).Picture := nil;
end;
end;
Result if and jpg error #53 (file not found), but it exists and first condiction of FileExists func is respected. (checked by debug)
What' s error?
Thanx
TGD
I'm trying to import a jpg image from a directory using BeforePrint.
Procecedure sounds :
procedure TStmpTab.StTabBeforePrint(Memo: TStringList; View: TfrView);
var cStr: string;
begin
if View.Name = 'Picture1' then
begin
cStr := Trim(DM.cPath + 'Scanner\' + IntToStr(DM.ArcScaL.FieldByName ('NroCip').AsInteger) +
DM.ArcScaL.FieldByName('NroDoc').AsString + '.jpg');
if FileExists(cStr) then
(StTab.FindObject('Picture1') as TfrPictureView).Picture.LoadFromFile(cStr)
else
(StTab.FindObject('Picture1') as TfrpictureView).Picture := nil;
end;
end;
Result if and jpg error #53 (file not found), but it exists and first condiction of FileExists func is respected. (checked by debug)
What' s error?
Thanx
TGD
Comments
2.34. How to print a picture that stored in a file?
a) use TfrReport.OnBeforePrint event:
if View.Name = 'Picture1' then
TfrPictureView(View).Picture.LoadFromFile(...);
if View.Name = 'Picture1' then
TfrPictureView(View).Picture.LoadFromFile(...);
Already tried before to post my example... it doesent works same error #53
Any other ideas?
Basically I' ve to build both path and file name at runtime before to load it and print; if I write something like ..LoadFromFile('C:\Images\Img01.jpg') it works, but
if it refer the path from a prevalorized variable it doesen't find correct path and image name. May u test it for me and send an example by mail? thanx
LoadFromFile('C:\Images\Img01.jpg') it works,
so either your variable's value is wrong or
you need to pass the opening and closing apostrophes
LoadFromFile('+varname+');
check to make sure your variable contains the complete path and file extension.
Herein is the right code:
procedure TStmpTab.StTabBeforePrint(Memo: TStringList; View: TfrView);
var cStr: string;
begin
if View.Name = 'Picture1' then
begin
cStr := Trim(DM.cPath + 'Scanner\' + IntToStr(DM.ArcScaL.FieldByName('NroCip').AsInteger) +
DM.ArcScaL.FieldByName('NroDoc').AsString + '.jpg');
if FileExists(cStr) then
(StTab.FindObject('Picture1') as TfrPictureView).Picture.Bitmap.LoadFromFile(cStr)
else
(StTab.FindObject('Picture1') as TfrpictureView).Picture.Bitmap := nil;
end;
I added .Bitmap to incapsulate LoadFromFile func and not just picture.LoadFromFile
it works both with
(StTab.FindObject('Picture1') as TfrPictureView).Picture.Bitmap.LoadFromFile(cStr)
and
TfrPictureView).Picture.Bitmap.LoadFromFile(cStr)
cheers
thanks for suggestions. I tried LoadFromFile('+myVar+')
Same #53 error
I already debugged instructiond and Fileexists(myDir) reports true..
if I add .Bitmap, image is displayed.
// wpath string global set in forms onshow event
WPath := ExtractFilePath(ParamStr(0));
procedure TForm1.frReport1BeforePrint(Memo: TStringList; View: TfrView);
VAR
cstr:string;
begin
cstr := wpath+'mytest3.jpg';
if View.Name = 'Picture1' then
BEGIN
if FileExists(cStr) then
begin
TfrPictureView(View).Picture.LoadFromFile(cstr);
end
else
begin
// showmessage(cstr +' not found');
end;
end;
end;
Variable is perfectly valorized (otherwise no chance to pass the Fileexists() condiction, but it doesent works except if I cast bitmap to picture.
I noted anyway, to had same problem when I valorize an TImage comp using same LoadFromFile() func.
Image1.Picture.LoadFromFile(myVar) it doesent works,
Image1.Picture.Bitmap.LoadFromfile(myVah) works.
I'm currently using XP with SP2, and some Kernel changement is the problem, I guess.
what's important to found solution!
Best