Home Subreports

Creating groups id dynamically created subreports

edited May 2005 in Subreports
I am unable to create groups in dynamically created subreports. Everything
works until I try to assign the group to the TppChildReport.

I get an Access Violation when printing.

I use Delphi 7, RB 9.02.

I the documentation there is a property for TppChildReport called SetParent.
I cannot access this property

Here's my (simplified) code:

procedure:
var

rpt: TppReport;
subRpt: TppSubReport;
childRpt: TppChildReport;
grp: TppGroup;
grpHb: TppGroupHeaderBand;

begin

jit.RecordCount := 3;

rpt := TppReport.Create(Self);
rpt.PrinterSetup.Orientation := poLandscape;

jit.DefineField('Field1', dtString, 100);
jit.DefineField('Field2', dtString, 100);

/////rpt.DetailBand.Height := 0.2; (old)
rpt.DetailBand.PrintHeight := phDynamic;

subRpt := TppSubReport.Create(Self);
subRpt.Band := rpt.DetailBand;
subRpt.CreateReport( rpt);
subRpt.PrintBehavior := pbSection;
subRpt.Report.PassSetting := psTwoPass;
subRpt.ResetPageNo := false;

childRpt := TppChildReport.Create(subRpt);

childRpt1.Parent := subRpt; //????

///subRpt.AddChild(childRpt);
//subRpt.SetReportProperty(childRpt);

childRpt.CreateDefaultBands;
childRpt.DataPipeline := jit;
//subRpt1.DataPipeline := jit;

with TppDBText.Create(Self) do
begin
Band := childRpt.DetailBand;
DataField := 'Field1';
DataPipeLine := jit;
Left := 0;
Width := 100;
end;

with TppDBText.Create(Self) do
begin
Band := childRpt.DetailBand;
DataField := 'Field2';
DataPipeLine := jit;
Left := 100;
Width := 100;
end;

grp := TppGroup.Create(Self);
grp.BreakName := 'Field2';
grp.BreakType := btDataField;
grp.DataPipeline := jit;
grp.NewPage := false;
grp.Report := childRpt
grpHb := TppGroupHeaderBand.Create(Self);
grpHb.Height := 0.2;
//grpHb.Report := childRpt;
grpHb.Group := grp;

with TppLabel.Create(Self) do
begin
Band := grpHb;
Left := 0;
Width := 100;
Caption := 'Break';
end;

rpt.Print;

Comments

  • edited May 2005
    Hi Tom,

    ----------------------------------------------------
    Tech Tip: Creating a Group in Code
    ----------------------------------------------------


    How can I dynamically create a report group at run-time?


    example code:
    -------------

    uses
    ppClass, ppGroup, ppClasUt;


    function AddGroupToReport(aBreakName: String; aDataPipeline:
    TppDataPipeline; aReport: TppCustomReport);
    var
    lGroup: TppGroup;
    lGroupBand: TppGroupBand;

    begin


    {add group to report}
    lGroup := TppGroup(ppComponentCreate(aReport, TppGroup));

    lGroup.Report := aReport;

    lGroup.BreakName := aBreakName;
    lGroup.DataPipeline := aDataPipeline;

    {add group header and footer bands }
    lGroupBand := TppGroupBand(ppComponentCreate(aReport,
    TppGroupHeaderBand));
    lGroupBand.Group := lGroup;

    lGroupBand := TppGroupBand(ppComponentCreate(aReport,
    TppGroupFooterBand));
    lGroupBand.Group := lGroup;


    end; {procedure, AddGroupToReport}


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.