Возможно ли создать отчет полностью во время выполнения программы, т.к. количество столбцов, их тип и источник данных для них могут меняться во время работы программы.
// Create MasterHeader Band ==================================================
frHeaderBand := TfrBandView.Create;
frHeaderBand.SetBounds( 0, 110, 0, 17); // Top and Height in Pixels
frHeaderBand.BandType := btMasterHeader;
frHeaderBand.Prop := True;
frPage.Objects.Add( frHeaderBand);
// Create MasterData Band ===
frDataBand := TfrBandView.Create;
frDataBand.SetBounds( 0, 130+17, 0, 20); // Top and Height in Pixels
frDataBand.BandType := btMasterData;
frDataBand.DataSet := 'frDBDataSet';
frPage.Objects.Add( frDataBand);
CurrLeft := frPage.pgMargins.Left;
// Create Data Fields ========================================================
for i:=0 to frDBDataSet.Dataset.Fields.Count-1 do begin
CurrWidth := 7 * frDBDataSet.Dataset.Fields.DisplayWidth; // besser: Canvas.TextWidth
if CurrWidth > frPage.Prop -frPage.pgMargins.Left -frPage.pgMargins.Right then
CurrWidth := frPage.Prop -frPage.pgMargins.Left -frPage.pgMargins.Right;
if CurrLeft + CurrWidth + frPage.pgMargins.Right > frPage.Prop then begin
frReport.Pages.Add;
frPage := frReport.Pages[frReport.Pages.Count-1];
with frPage do begin
ChangePaper( pgSize, pgWidth, pgHeight, pgBin, TPrinterOrientation(poLandscape));
frPage.pgMargins.Left := 20;
frPage.pgMargins.Right := 20;
frPage.pgMargins.Top := 20;
frPage.pgMargins.Bottom := 20;
if poLandscape = poLandscape then
frPage.pgMargins.Top := 50
else
frPage.pgMargins.Left := 50;
end;
CurrLeft := frPage.pgMargins.Left;
// Create MasterHeader Band ===
frHeaderBand := TfrBandView.Create;
frHeaderBand.SetBounds( 0, 110, 0, 17); // Top and Height in Pixels
frHeaderBand.BandType := btMasterHeader;
frHeaderBand.Prop := True;
frPage.Objects.Add( frHeaderBand);
// Create MasterData Band ===
frDataBand := TfrBandView.Create;
frDataBand.SetBounds( 0, 130+17, 0, 20); // Top and Height in Pixels
frDataBand.BandType := btMasterData;
frDataBand.DataSet := 'frDBDataSet';
frPage.Objects.Add( frDataBand);
end;
Комментарии
http://www.fastreports.net/ru/forum/index.php?showtopic=380
procedure TForm1.InitReport( ADataset: TDataset);
var
frPage: TfrPage;
frTitleBand, frHeaderBand, frDataBand: TfrBandView;
frView: TfrView;
i: Integer;
CurrLeft, CurrWidth: Integer;
begin
frDBDataSet.DataSet := ADataset;
// Create Page
frReport.Pages.Clear;
frReport.Pages.Add;
frPage := frReport.Pages[0];
with frPage do begin
ChangePaper( pgSize, pgWidth, pgHeight, pgBin, TPrinterOrientation( poLandscape ));
frPage.pgMargins.Left := 20;
frPage.pgMargins.Right := 20;
frPage.pgMargins.Top := 20;
frPage.pgMargins.Bottom := 20;
if poLandscape = poLandscape then
frPage.pgMargins.Top := 50
else
frPage.pgMargins.Left := 50;
end;
CurrLeft := frPage.pgMargins.Left;
// Create ReportTitle Band ===================================================
frTitleBand := TfrBandView.Create;
frTitleBand.SetBounds( 0, 20, 0, 70); // Top and Height in Pixels
frTitleBand.BandType := btReportTitle;
frPage.Objects.Add( frTitleBand);
// Create Memo
frView := TfrMemoView.Create;
frView.SetBounds( 20, 50, 200, 30);
frView.BandAlign := baWidth;
frView.Prop := frtaLeft;
frView.Prop := 2;
frView.Prop := 20;
FrView.Memo.Add( edReportTitle.Text);
frPage.Objects.Add( frView);
// Create MasterHeader Band ==================================================
frHeaderBand := TfrBandView.Create;
frHeaderBand.SetBounds( 0, 110, 0, 17); // Top and Height in Pixels
frHeaderBand.BandType := btMasterHeader;
frHeaderBand.Prop := True;
frPage.Objects.Add( frHeaderBand);
// Create MasterData Band ===
frDataBand := TfrBandView.Create;
frDataBand.SetBounds( 0, 130+17, 0, 20); // Top and Height in Pixels
frDataBand.BandType := btMasterData;
frDataBand.DataSet := 'frDBDataSet';
frPage.Objects.Add( frDataBand);
CurrLeft := frPage.pgMargins.Left;
// Create Data Fields ========================================================
for i:=0 to frDBDataSet.Dataset.Fields.Count-1 do begin
CurrWidth := 7 * frDBDataSet.Dataset.Fields.DisplayWidth; // besser: Canvas.TextWidth
if CurrWidth > frPage.Prop -frPage.pgMargins.Left -frPage.pgMargins.Right then
CurrWidth := frPage.Prop -frPage.pgMargins.Left -frPage.pgMargins.Right;
if CurrLeft + CurrWidth + frPage.pgMargins.Right > frPage.Prop then begin
frReport.Pages.Add;
frPage := frReport.Pages[frReport.Pages.Count-1];
with frPage do begin
ChangePaper( pgSize, pgWidth, pgHeight, pgBin, TPrinterOrientation(poLandscape));
frPage.pgMargins.Left := 20;
frPage.pgMargins.Right := 20;
frPage.pgMargins.Top := 20;
frPage.pgMargins.Bottom := 20;
if poLandscape = poLandscape then
frPage.pgMargins.Top := 50
else
frPage.pgMargins.Left := 50;
end;
CurrLeft := frPage.pgMargins.Left;
// Create MasterHeader Band ===
frHeaderBand := TfrBandView.Create;
frHeaderBand.SetBounds( 0, 110, 0, 17); // Top and Height in Pixels
frHeaderBand.BandType := btMasterHeader;
frHeaderBand.Prop := True;
frPage.Objects.Add( frHeaderBand);
// Create MasterData Band ===
frDataBand := TfrBandView.Create;
frDataBand.SetBounds( 0, 130+17, 0, 20); // Top and Height in Pixels
frDataBand.BandType := btMasterData;
frDataBand.DataSet := 'frDBDataSet';
frPage.Objects.Add( frDataBand);
end;
// Field-Caption
frView := TfrMemoView.Create;
frView.SetBounds( CurrLeft, 110, CurrWidth, 17);
FrView.Memo.Add( frDBDataSet.Dataset.Fields.DisplayLabel);
FrView.Prop := 15;
FrView.Prop := clNavy;
FrView.Prop := clWhite;
FrView.Prop := 2; // fsBold;
frPage.Objects.Add( frView);
// Field-Data
frView := TfrMemoView.Create;
frView.SetBounds( CurrLeft, 130+17, CurrWidth, 20);
FrView.Memo.Add('.FieldName + '"]');
FrView.Prop := 15;
frPage.Objects.Add( frView);
CurrLeft := CurrLeft + CurrWidth;
end;
end;