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

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 7:40AM
    fROM FAQ.TXT
    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(...);

    ;)
  • TGDTGD
    edited 7:40AM
    gordk wrote:
    fROM FAQ.TXT
    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(...);

    ;)
    a) use TfrReport.OnBeforePrint event:

    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
  • gordkgordk St.Catherines On. Canada.
    edited 7:40AM
    This should be a clue
    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.
    ;)
  • TGDTGD
    edited 7:40AM
    gordk wrote:
    fROM FAQ.TXT
    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(...);

    ;)
    Something is wrong. Or tip in FastReport site or in 2.57 source.
    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 ;)
  • TGDTGD
    edited 7:40AM
    gordk wrote:
    This should be a clue
    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.
    ;)
    Hi Gord

    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.
    ;)
  • gordkgordk St.Catherines On. Canada.
    edited 7:40AM
    this works fine for me no need for extra find and cast
    // 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;

    ;)
  • TGDTGD
    edited 7:40AM
    gordk wrote:
    this works fine for me no need for extra find and cast
    // 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;

    ;)
    Dunno Gord.

    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

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.