Report with pictures from files

I have a report that will be created from a database typically with many thousand entries. For each entry there will be a different image that needs to be displayed, the databse just contains a token that allows me to find the relevant image (from disk) to display.

New to FR so not sure how I go about this.

Any help appreciated.

Comments

  • edited 12:43AM
    ...
    Any help appreciated.
    Just have a look at FR compiled demo - Basic reports' example Memos and pictures (definition is in 8.fr3).
    You should read FR User Manual chapters 2.13 and 2.14 - you'll find a lots of information over there.
  • gordkgordk St.Catherines On. Canada.
    edited 12:43AM
    since your datafield only contains file locations
    create a variable and connect it to the datafield that has your file info.
    in the obp event of the pictureview object or the band that contains the pictureview, write code to load from file.
    ie
    picture1.picture.loadfromfile(<variablename>);
  • Thanks for the replies - I'll try and look at implementing something a bit later.

    Just one clarification which might make a difference [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> The db does'nt contain an image, it contains a reference that I use to create an image - so basically as each record is processed by fast report I will need some logic to copy (and modify - but that is in hand) the image from one location to another and it is this second location that i will be able to pass to fast Reports. Alternatively I could pass a buffer containing a jpg/png etc - is this doable? Thanks[/img]
  • edited 12:43AM
    ...
    Alternatively I could pass a buffer containing a jpg/png etc - is this doable?
    As Gordk said: you need to Load picture from disk - from any file you specify as a parameter of LoadFromFile(<Path.fileName.ext>).

    TPicture object doesn't have LoadFromStream() method [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> So after you finish a manipulation with your picture according to a certain table / query row, you must save that picture anywhere on disk(s) and then use[/img]LoadFromFile(<Path.fileName.ext>) to read that just saved file.

    Alternative to save / load picture to / from file is to make use of your database (temporary or standard) table with long binary (or similar) field. If you try this option then, when your final picture is ready and is still kept in a memory save it to a blob field in this table and have TfrxPictureView to read this field from the table.
  • gpigpi
    edited 12:43AM
    wrote:
    The db does'nt contain an image, it contains a reference that I use to create an image - so basically as each record is processed by fast report I will need some logic to copy (and modify - but that is in hand) the image from one location to another and it is this second location that i will be able to pass to fast Reports.
    You can use picture1.picture.loadfromfile(<variablename>) in script. Also you can use TfrxPictureView.FileLink property or load picture in Delphi's code in TfrxReport.OnBeforePrint event
  • TonyAlloaTonyAlloa Alloa, Scotland
    edited 12:43AM
    This might help you. this is used in a db that creates a PDF file of small thumbnails of gfx in the db

    the FileExists function is added at runtime using the report.script.addmethod
    type
      TMainForm = class(TForm)
       ....
      private
        { Private declarations }
      public
        { Public declarations }
        function FileExists(s: string): boolean;
        function CallMethod(Instance: TObject; ClassType: TClass;
          const MethodName: string; var Params: Variant): Variant;
      end;
    
    function TMainForm.FileExists(s: string): boolean;
    begin
      result := SysUtils.FileExists(s);
    end;
    
    function TMainForm.CallMethod(Instance: TObject; ClassType: TClass;
      const MethodName: string; var Params: Variant): Variant;
    begin
      // dispatch the method call 
      if MethodName = 'FILEEXISTS' then
        result := FileExists(Params[0]);
      ...
    
    procedure TMainForm.FormCreate(Sender: TObject);
    const
      g='User Functions/Procedures';
    begin
      // frGlobalUnit contains standard types and functions
      frxReport.Script.Parent := fsGlobalUnit;
      frxReport.Script.AddMethod('function FileExists(fName: String): Boolean',
        MainForm.CallMethod,g,'Checks if a given FileName <fName> Exists');
       ....
    

    in the code of the report:
    function CheckFileName(s: string): string;
    begin
      s := VarToStr(s);
      s := Trim(s);
      if s > '' then begin
        result := s;
        if not FileExists(s) then begin
          //
          // filename given, but not found
          // so write to error log
          //if (dbg=TRUE) then begin
         //  s := 'file not found: ' + s + #13#10;
         //   fs.Write(s, Length(s));
         // end;
          // zero the string
          result := '';
        end;
      end;
    end;
    
    procedure BeforePrint(fName: string; img: TfrxPictureView);
    begin
      fName := CheckFileName(fName);
      if (fName > '') then
        img.picture.LoadFromFile(fName)
      else
        img.Picture := nil;
    // or add a gfx not found img?
    //  img.picture.LoadFromFile('error.jpg')
    end;
    
    procedure imgBackOnBeforePrint(Sender: TfrxComponent);
    begin
      BeforePrint(<DisksDB."Back">, imgBack);
    end;
    
    procedure imgBackOnAfterPrint(Sender: TfrxComponent);
    begin
      // nil the component or it will carry over to next record
      imgBack.Picture := nil;
    end;
    
  • edited 12:43AM
    gordk wrote: »
    since your datafield only contains file locations
    create a variable and connect it to the datafield that has your file info.
    in the obp event of the pictureview object or the band that contains the pictureview, write code to load from file.
    ie
    picture1.picture.loadfromfile(<variablename>);

    I have the same scenario as the original writer and I found your instructions very helpful.

    However, as the FastReports version shipped with Delphi XE3 does not siupport events I had to solve the issue in another way:
    1) Assign the datafield into a variable, e.g. 'filename'
    2) Assign the FileLink property of the picture object as the variable, i.e '[filename]'

    Works nicely at least in FR 4.12.13

    The above is for anyone face the same scenario again.

    Kr, Kalle
  • gpigpi
    edited 12:43AM
    wrote:
    However, as the FastReports version shipped with Delphi XE3 does not siupport events I had to solve the issue in another way:
    But you can use TfrxReport.OnBeforePrint event

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.