ich möchte einen Fastreport komplett via code erzeugen, meine Daten kommen aus einer FDmemTable.
hier der aktuelle Code
Delphi-Quellcode:
procedure TForm2.BitBtn_FastReportClick(Sender: TObject);
var
Report: TfrxReport;
Page: TfrxReportPage;
DataPage: TfrxDataPage;
Band: TfrxBand;
DataBand: TfrxMasterData;
Memo: TfrxMemoView;
Memo_1: TfrxMemoView;
Memo_2: TfrxMemoView;
Memo_3: TfrxMemoView;
Memo_4: TfrxMemoView;
DataSet: TfrxDataset;
frxDBDataSet: TfrxDBDataset;
PictureView: TfrxPictureView;
Frxdataset: TfrxDataset;
ItemIndex: Integer;
ItemCount: Integer;
begin
FileName := LabeledEdit.text;
Report := TfrxReport.Create(nil);
try
{ add a dataset to the list of ones accessible for a report }
Report.DataSets.Add(frxDBDataset1);
DataPage := TfrxDataPage.Create(Report);
{ add a page }
Page := TfrxReportPage.Create(Report);
{ create a unique name }
Page.CreateUniqueName;
{ set sizes of fields, paper and orientation by default }
// Page.SetDefaults;
{ add a report title band }
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
{ it is sufficient to set the «Top» coordinate and height for a band }
{ both coordinates are in pixels }
Band.Top := 0;
Band.Height := 20;
{ add an object to the report title band }
Memo := TfrxMemoView.Create(Band);
Memo.CreateUniqueName;
Memo.text := 'Hello FastReport!';
Memo.Height := 20;
{ this object will be stretched according to band’s width }
Memo.Align := baWidth;
{ add the masterdata band }
DataBand := TfrxMasterData.Create(Page);
DataBand.CreateUniqueName;
DataBand.DataSet := frxDBDataset1;
{ the Top coordinate should be greater than the previously added band’s top + height }
DataBand.Top := 100;
DataBand.Height := 300;
{ add an object on master data }
Memo_1 := TfrxMemoView.Create(DataBand);
Memo_1.CreateUniqueName;
{ connect to data }
Memo_1.DataSet := frxDBDataset1;
Memo_1.DataField := 'Index';
Memo_1.SetBounds(0, 0, 100, 20);
{ adjust the text to the right object’s margin }
Memo_1.HAlign := haRight;
Memo_2 := TfrxMemoView.Create(DataBand);
Memo_2.CreateUniqueName;
{ connect to data }
Memo_2.DataSet := frxDBDataset1;
Memo_2.DataField := 'Object';
Memo_2.SetBounds(150, 0, 100, 20);
Memo_3 := TfrxMemoView.Create(DataBand);
Memo_3.CreateUniqueName;
{ connect to data }
Memo_3.DataSet := frxDBDataset1;
Memo_3.DataField := 'Type';
Memo_3.SetBounds(300, 0, 100, 20);
Memo_4 := TfrxMemoView.Create(DataBand);
Memo_4.CreateUniqueName;
Memo_4.Font.Height := 8;
Memo_4.Font.Color := clred;
{ connect to data }
Memo_4.DataSet := frxDBDataset1;
Memo_4.DataField := 'newBMP';
Memo_4.SetBounds(10, 40, 1400, 20);
PictureView:=TfrxPictureView.Create(DataBand);
PictureView.SetBounds(100,100,300,300);
PictureView.Picture.LoadFromFile('E:\demo.bmp');
PictureView.AutoSize := true;
PictureView.Stretched := true;
{ show the report }
Report.ShowReport;
Report.FileName := FileName;
Report.PrepareReport(True);
// Report.Export(TfrxPDFExport, FileName);
finally
Report.Free;
end;
end;
Ich have aktuell folgendes Problem:
Der Name der zu plottenden Grafik soll nicht immer
PictureView.Picture.LoadFromFile('E:\demo.bmp');
sein
sondern der Wert aus meiner FDMEmtabelle in der Spalte/Field newBMP . Wie greife ich hier auf den richtigen wert zu ?
Im nächsten Schritt möchte ich dann noch eine Bildunterschrift einfügen, diesen String würde ich auch erst zur Berichtserzeugung erstellen.