因为照片是jpg格式,且保存在文件夹中而不是保存在数据库中,数据库中只保存文件路径。怎么实现在报表预览时动态载入照片?
FastReport能不能实现?如果不能,有没有其它能实现的报表控制?
我用的是Delphi6.

解决方案 »

  1.   

    刚写的,测试通过procedure TForm1.Button1Click(Sender: TObject);
    var FRName,JpgPath:string;
        t1:TfrPictureView;
    begin
      FRName:='c:\myfr.frf';
      JpgPath:='c:\1.jpg';//你可以把数据库中保存的文件路径赋值给JpgPath  frReport1.LoadFromFile(FRName);  t1:=TfrPictureView(frReport1.FindObject('Picture1'));//这两句实现动态载入照片,Picture1是你报表中显示照片的frPictureView控件名字。
      if t1<>nil then t1.Picture.LoadFromFile(JpgPath);  frReport1.ShowReport;
    end;
      

  2.   

    这样我做过了!但是我的照片字段也在MasterData段中,也就是明细。对应每笔记录的照片不一样的。
    按上述代码得到的结果是,所有照片都一样!
      

  3.   

    很遗憾,frPictureView不是数据感知控件,不能像frMemoView一样连接数据库字段。
      

  4.   

    试试frPictureView的tag属性,在打开的对话框中选择字段看看。
      

  5.   

    问题我自己解决了,道理很简单:
    主要是要在适当的时候载入照片。我原来是在报表的OnProgress事件中载入照片的,但这时的报表还算是模板,故预览时就会被固定为一个照片。现在把载入照片的代码放到报表的OnBefore事件中执行,显示结果就正确了,因为这时报表已经不是模板,而是预览后的报表!
    完整的代码如下:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, FR_Class, jpeg, ExtCtrls, DBCtrls, DB, FR_DSet,
      FR_DBSet, ADODB;type
      TForm1 = class(TForm)
        Image1: TImage;
        frReport1: TfrReport;
        Button1: TButton;
        Button2: TButton;
        ADOConnection1: TADOConnection;
        ADOTable1: TADOTable;
        DataSource1: TDataSource;
        frDBDataSet1: TfrDBDataSet;
        ADOTable1EmpNo: TStringField;
        ADOTable1EmpName: TStringField;
        ADOTable1Photo: TBlobField;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure frReport1BeforePrint(Memo: TStringList; View: TfrView);
      private
        { Private declarations }
        PV:TfrPictureView;
        procedure LoadPhoto;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
    var
      i:Integer;
    begin
      with ADOTable1 do
      begin
        First;
        for i:=0 to RecordCount - 1 do
        begin
          LoadPhoto;
          Next;
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      PV:=(frReport1.FindObject('Picture1') as TfrPictureView);
      frReport1.ShowReport;
    end;procedure TForm1.LoadPhoto;
    var
      S,FileName:String;
    begin
      S:= trim(ADOTable1.FieldByName('EmpNo').AsString);
      FileName:='C:\Documents and Settings\Administrator\My Documents\My Pictures\'
            + S +'.jpg';
      if FileExists(FileName) then
      begin
        PV.Picture.LoadFromFile(FileName);
      end;
    end;procedure TForm1.frReport1BeforePrint(Memo: TStringList; View: TfrView);
    begin
      LoadPhoto;
    end;end.
      

  6.   

    对了,上面的Button2Click过程中的代码是测试用的,不要误会!
    另:TfrPictureView可以设置数据库字段的,只不过不是通过双击设置,而是在属性对话框中设置,按F11显示FastReport的属性对话框。