How to print pictures with loadfromfile and filename from database?

edited 11:04PM in FastReport 4.0
Hello,

I have a database with books. For most of them there ist a jpg-file in a subdirectory of the application. the name of the file ist the ISBN with the extension .jpg
I tried to show the picture in a report as following:
- put a picture in the data band
- create a piece of code generating the filename
- fill the pictur with LoadFromFile

The code is:
procedure Band4OnBeforePrint(Sender: TfrxComponent);
var 
  ISBN_DB, ISBN:String;
  i:integer;                        
    
begin
    ISBN :='';
    ISBN_DB := [frDSDruck."ISBN"];
    for i:=1 to length(ISBN_DB) do
       if ISBN_DB[i] <>' ' then ISBN := ISBN+ISBN_DB[i];      // replace blank with empty string  
    if length(ISBN) >9 then
       picture1.loadfromfile('C:\Programdata\bisam\daten\jpg\'+ISBN+'.jpg');
    memo19.text:='C:\Programdata\bisam\daten\jpg\'+ISBN+'.jpg';   // test: show me the filename
end;

In memo19 I print the filename for testing
-> it alway show the right value, but all pictures contains the same image (the image for the last book in the list).

What is wrong in my coding or report?

Comments

  • edited 11:04PM
    Haegar wrote: »
    Hello,

    I have a database with books. For most of them there ist a jpg-file in a subdirectory of the application. the name of the file ist the ISBN with the extension .jpg
    I tried to show the picture in a report as following:
    - put a picture in the data band
    - create a piece of code generating the filename
    - fill the pictur with LoadFromFile

    The code is:
    procedure Band4OnBeforePrint(Sender: TfrxComponent);
    var 
      ISBN_DB, ISBN:String;
      i:integer;                        
        
    begin
        ISBN :='';
        ISBN_DB := [frDSDruck."ISBN"];
        for i:=1 to length(ISBN_DB) do
           if ISBN_DB[i] <>' ' then ISBN := ISBN+ISBN_DB[i];      // replace blank with empty string  
        if length(ISBN) >9 then
           picture1.loadfromfile('C:\Programdata\bisam\daten\jpg\'+ISBN+'.jpg');
        memo19.text:='C:\Programdata\bisam\daten\jpg\'+ISBN+'.jpg';   // test: show me the filename
    end;
    

    In memo19 I print the filename for testing
    -> it alway show the right value, but all pictures contains the same image (the image for the last book in the list).

    What is wrong in my coding or report?


    Hello!

    Try this before "loadfromfile":

    Picture1.Clear;

    I think "loadfromfile" command keeps the last value used.

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.