下面的代码以每一行打4副图像为例子,图片放在c:/test目录里在Master Data里放4个TfrPictureView,依次为Picture1,Picture2,Picture3,Picture4frReport1.StoreInDFM:=True;...implementation{$R *.dfm}procedure TForm1.CreateCDS;
begin
if ClientDataSet1.Active then
ClientDataSet1.Active:=False;
ClientDataSet1.FieldDefs.Clear;
ClientDataSet1.FieldDefs.Add('Pic1',ftString,50);
ClientDataSet1.FieldDefs.Add('Pic2',ftString,50);
ClientDataSet1.FieldDefs.Add('Pic3',ftString,50);
ClientDataSet1.FieldDefs.Add('Pic4',ftString,50);
ClientDataSet1.CreateDataSet;
end;
procedure TForm1.Button1Click(Sender: TObject);const c_Path='c:/test/';var SR:TSearchRec;
iCount:integer;
begin
CreateCDS;
iCount:=1;
if FindFirst(c_Path+'*.jpg',faAnyFile,SR)=0 then
begin
ClientDataSet1.Append;
repeat if (SR.Name='.') or (SR.Name='..') then
Continue;
if iCount mod 5=0 then
begin
if ClientDataSet1.State<>dsBrowse then
ClientDataSet1.Post;
ClientDataSet1.Append;
iCount:=1;
end;
ClientDataSet1.FieldByName('Pic'+IntToStr(iCount)).AsString:=c_Path+SR.Name;
inc(iCount);
until FindNext(SR)<>0;
end;
if ClientDataSet1.RecordCount=0 then
exit;
frReport1.ShowReport;
end;
procedure TForm1.frReport1begin
Band(Band: TfrBand);var Pic:TfrPictureView;
frView:TfrView;
sPath:string;
begin
if Band.Name='MasterData1' then
begin
frView:=frReport1.FindObject('Picture1');
if frView is TfrPictureView then
begin
pic:=TfrPictureView(frView);
sPath:=ClientDataSet1.fieldByName('Pic1').AsString;
if FileExists(sPath) then
pic.Picture.LoadFromFile(sPath);
end;
frView:=frReport1.FindObject('Picture2');
if frView is TfrPictureView then
begin
pic:=TfrPictureView(frView);
sPath:=ClientDataSet1.fieldByName('Pic2').AsString;
if FileExists(sPath) then
pic.Picture.LoadFromFile(sPath);
end;
frView:=frReport1.FindObject('Picture3');
if frView is TfrPictureView then
begin
pic:=TfrPictureView(frView);
sPath:=ClientDataSet1.fieldByName('Pic3').AsString;
if FileExists(sPath) then
pic.Picture.LoadFromFile(sPath);
end;
frView:=frReport1.FindObject('Picture4');
if frView is TfrPictureView then
begin
pic:=TfrPictureView(frView);
sPath:=ClientDataSet1.fieldByName('Pic4').AsString;
if FileExists(sPath) then
pic.Picture.LoadFromFile(sPath);
end;
end;
end;