Creating report at runtime

edited January 2009 in FastReport 4.0
Hi,

I would like to create a report at runtime with Delphi. I have a problem when I try to create report with GroupHeader and GroupFooter. If I call "DesingReport" I don't have a problem, but if I call "ShowReport" my group header and footer does'nt appear. This is my code :


procedure TfReportMaster.GenerateReport(aQuery : TPellucQuery);
var
lDSReport : TfrxDBDataset;
lReport : TfrxReport;
lPage : TfrxReportPage;
lPageHeader : TfrxPageHeader;
lMasterData : TfrxMasterData;
lGroupHeader : TfrxGroupHeader;
lGroupFooter : TfrxGroupFooter;
begin
//Cr?©ation du dataset pour le rapport
lDSReport := TfrxDBDataset.Create(Self);
lDSReport.DataSet := aQuery;
lDSReport.UserName := 'qryReport';
//Cr?©ation du rapport
lReport := TfrxReport.Create(Self);
lReport.DataSets.Add(lDSReport);
//Cr?©ation de la page
lPage := TfrxReportPage.Create(lReport);
lPage.CreateUniqueName;
lPage.SetDefaults;
//Initialise le format de papier
lPage.PaperSize := DMPAPER_LETTER;
//Initialise l'orientation du papier
lPage.Orientation := poLandscape;

//Cr?©ation de l'ent??te de la page
lPageHeader := TfrxPageHeader.Create(lPage);
lPageHeader.CreateUniqueName;
lPageHeader.SetBounds(0, 0, lPage.Width - 75.6, 44);
//Cr?©ation du m?©mo pour le titre du rapport
with TfrxMemoView.Create(lPageHeader) do
begin
CreateUniqueName;
Align := baCenter;
AutoWidth := True;
HAlign := haCenter;
SetBounds(0, 4, 0, 24);
Font.Size := 12;
Font.Style := [fsBold, fsUnderline];
Text := 'RAPPORT';
end;
//Cr?©ation du m?©mo pour le tri par
with TfrxMemoView.Create(lPageHeader) do
begin
CreateUniqueName;
Align := baCenter;
AutoWidth := True;
HAlign := haCenter;
SetBounds(0, 28, 0, 16);
Text := 'SORT BY';
end;



//Cr?©ation du MasterData
lMasterData := TfrxMasterData.Create(lPage);
with lMasterData do
begin
//Initialise le nom du MasterData
Name := 'MasterData1';
DataSet := lDSReport;
Height := 20;
end;
with TfrxMemoView.Create(lMasterData) do
begin
CreateUniqueName;
Align := baClient;
Frame.Typ := [ftLeft, ftRight, ftTop, ftBottom];
Text := 'DETAIL';
end;

//Group footer creation
lGroupFooter := TfrxGroupFooter.Create(lReport.Pages[0]);
lGroupFooter.Parent := lReport.Pages[0];
with lGroupFooter do
begin
CreateUniqueName;
SetBounds(0, 0, lPage.Width - 75.6, 20);
end;
with TfrxMemoView.Create(lGroupFooter) do
begin
CreateUniqueName;
Align := baClient;
Frame.Typ := [ftLeft, ftRight, ftTop, ftBottom];
Text := 'GROUP FOOTER';
end;

//Group header creation
lGroupHeader := TfrxGroupHeader.Create(lReport.Pages[0]);
lGroupHeader.Parent := lReport.Pages[0];
with lGroupHeader do
begin
CreateUniqueName;
SetBounds(0, 0, lPage.Width - 75.6, 20);
Condition := 'qryReport."CUSNUM"';
end;
with TfrxMemoView.Create(lGroupHeader[1]) do
begin
CreateUniqueName;
Align := baClient;
Frame.Typ := [ftLeft, ftRight, ftTop, ftBottom];
Text := 'GROUP HEADER';
end;
with TfrxMemoView.Create(lGroupHeader[1]) do
begin
CreateUniqueName;
AutoWidth := True;
SetBounds(8 , 32, 10, 16);
DataSet := lDSReport;
DataField := 'CUSNUM';
end;

//With this code, Groups does'nt appear
lReport.ShowProgress := True;
lReport.OldStyleProgress := True;
lReport.PrepareReport(True);
lReport.ShowPreparedReport;

//With this code, Groups appear
lReport.DesignReport;

lReport.Free;
lDSReport.Free;
end;

Please help me to resolve my problem
I use the latest FastReport Professionnal

Comments

  • gpigpi
    edited 2:19PM
    You must place bands in such order (set top property)
    PageHeader
    GroupHeader
    MasterData
    GroupFooter
  • edited 2:19PM
    EXCELLENT
    IT WORKS

    Thank you sir

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.