在快速报告中每行打印后插入不同的图片对象

时间:2014-06-27 06:38:24

标签: delphi delphi-xe5 fastreport firemonkey-fm2

我正在使用Firemonkey(Delphi XE5)开发一个应用程序,我正在使用快速报告4来打印数据。我使用TFrxUserDataSet来保存数据并打印这个,我在快速报告中使用MasterData band。

现在,我还需要在每行打印TBitamp,所以这里每条记录的位图都会有所不同。

有没有人知道我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以将外部图像文件加载到报告中的图片控件中。我正在使用脚本作为报告本身的一部分使用OnBeforePrint事件,如下所示:

PROCEDURE Data2OnBeforePrint(Sender: TfrxComponent);
VAR
  lFN               : STRING;
  lFP               : STRING;
BEGIN
  // Use the filename as found in the Media dataset fields
  lFP := Trim(< Media."ImagePath">);    // Images folder below Image Root Path
  lFN := Trim(< Media."FileName1">);    // Actual Image File Name

  WITH Picture2 DO BEGIN

    // NB: There is no checking in this example, it may be useful to do a 
    //     couple of checks before trying to load the image, especially if 
    //     the data is user entered
    LoadFromFile(ImageRootPath + IncludeTrailingSlash(lFP) + lFN);

    // Do whatever manipulations you want to with the loaded image...
    AutoSize := False;
    Width := 1620;
    Height := 1080;
    Top := 0;
    Left := (1920 - Width) / 2;

    HightQuality := True;    // Note the typo in the property name... HighQuality?
    KeepAspectRatio := True;
    Transparent := True;
    Stretched := NOT Picture3.AutoSize;
  END;
END;

请注意,我添加了一些用户函数,如ImageRootPath IncludeTrailingSlash(),以使脚本更容易。在尝试加载之前,您可以执行类似的操作来检查有效文件,以避免异常。

我的开发环境是带有FastReport FMX的Delphi XE5,它运行得很好。我正在搬到XE6和FR FMX 2,但我很确定这会很好。