Code based report

I try to create a report dynamically.

I put a  frxReport1 and a frxDataset on Datamodule form and connect it to an AdoQuery.

This AdoQuery delivered answers have a different amount of columns.

So I used the code from  > FastReport 4 Programmer's manual<

The Fast Report version  belongs to Delphi 10.1

 

procedure TDM2.bericht;

 var DataPage: TfrxDataPage;

    Page: TfrxReportPage;

     Band: TfrxBand;

     hband: Tfrxheader;

     DataBand: TfrxMasterData;

      Memo, me0, me1,me2: TfrxMemoView;

      ileft, i : integer;

      meField , topfield: TfrxMemoView;

 

  begin

      { clear a report }

      frxReport1.Clear;

      { add a dataset to the list of ones accessible for a report }

      frxReport1.DataSets.Add(frxDBDataSet1);{ add the "Data" page }

      DataPage := TfrxDataPage.Create(frxReport1);{ add a page }

      Page := TfrxReportPage.Create(frxReport1);{ create a unique name }

      Page.CreateUniqueName;{ set sizes of fields, paper and orientation by default }

      Page.SetDefaults;

      { modify paper’s orientation }

      Page.Orientation := poLandscape;

      { 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 := 30;

      { add an object to the report title band }

      Memo := TfrxMemoView.Create(Band);

      Memo.CreateUniqueName;

      Memo.Text := 'Strahlpumpen Übersicht ';

      Memo.Font.Size:=16;

      Memo.Height := 25;

      { this object will be stretched according to band’s width }

      Memo.Align := bawidth;

 

      hBand := Tfrxpageheader.Create(Page);

      hBand.CreateUniqueName;

     // Band.DataSet := frxDBDataSet1;

      hBand.Top := 50;

      hBand.Height := 20;

      Me0 := TfrxMemoView.Create(hBand);

      Me0.CreateUniqueName;

      Me0.Text := 'Spaltenüberschrift!';

      me0.Font.Size:=12;

      Me0.Height := 30;

 

      { 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 := 160;

      DataBand.Height := 20;

      { add an object on master data }

 for I := 0 to adoquery3.Fields.Count-1 do begin

           mefield:= TfrxMemoView.Create(DataBand);

           mefield.Name:='Me_'+inttostr(i);

           mefield.dataset:= frxDBDataSet1;

           mefield.DataField:= adoquery3.Fields.Fields[i].FieldName;

           mefield.SetBounds(i*80, 40, 100, 20);

end; 

 

      { adjust the text to the right object’s margin }

    // Memo.HAlign := haRight;

      { show the report }

      frxReport1.ShowReport ;

  end;

 

This code snippet shows the Reportheader  and the data from the Adoquery.

My question is now, how can I show a pageheader with the column title ?

I think the pageheader will be the right choice .

 

      hBand := Tfrxpageheader.Create(Page);

      hBand.CreateUniqueName;

     // Band.DataSet := frxDBDataSet1;

      hBand.Top := 50;

      hBand.Height := 20;

      Me0 := TfrxMemoView.Create(hBand);

      Me0.CreateUniqueName;

      Me0.Text := 'Spaltenüberschrift!';

      me0.Font.Size:=12;

      Me0.Height := 30;

This code segment is not visible at the Report.

Who can help with a sample or can give me an advice where I could find more information.

Best Regards

Aussie1

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.