Example for "Creating a Group in Code"
Hi,
to find out how to do it, I've coded a sample-project based on a SELECT
over DBDEMOS.ORDERS.
Because needing sometime I'd like to share it with others.
If there's a place to store samples, I could send the .pas and .dfm.
_________
SELECT CustNo, OrderNo,
Sum(AmountPaid) AmountPaid, Count(*) Anz
FROM orders
Where CustNo <= 1351
Group By CustNo, OrderNo
Order By CustNo, OrderNo
_________
unit GroupByCodeFMU;
{
2007-01-04 Dietmar Brueckmann (db)
Tested on XP D6 rb9.03
Example-Form for "Creating a Group in Code" with Sum-Fields
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, Grids, DBGrids, DB, DBTables, ppCtrls, ppPrnabl, ppClass,
ppBands, ppCache, ppProd, ppReport, ppDB, ppComm, ppRelatv, ppDBPipe,
ppDBBDE, ppClasUt;
type
TfoGrouByCode = class(TForm)
DBGrid1: TDBGrid;
q: TQuery;
qCustNo: TFloatField;
qOrderNo: TFloatField;
qAmountPaid: TCurrencyField;
qAnz: TIntegerField;
sc: TDataSource;
rp: TppBDEPipeline;
rr: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppLabel1: TppLabel;
ppShape1: TppShape;
ppDBText1: TppDBText;
ppLabel2: TppLabel;
ppShape2: TppShape;
ppDBText2: TppDBText;
ppLabel3: TppLabel;
ppShape3: TppShape;
rdAmountPaid: TppDBText;
ppLabel4: TppLabel;
ppShape4: TppShape;
rdAnz: TppDBText;
rcAmountPaid: TppDBCalc;
ppDBCalc2: TppDBCalc;
ppSummaryBand1: TppSummaryBand;
procedure FormShow(Sender: TObject);
private
rgrCustNo : TppGroup;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
foGrouByCode: TfoGrouByCode;
implementation
{$R *.dfm}
function AddCalcToGroup(_rgr: TppGroup;_From: TppDBText): TppDBCalc;
begin
Result := TppDBCalc.Create(_rgr.Report);
Result.Name :=
Format('rc%s_%s',[_rgr.BreakName,_From.DataField]);
Result.DataField := _From.DataField;
Result.DataPipeline := _rgr.Report.DataPipeline;
Result.Band := _rgr.FooterBand;
Result.ResetGroup := _rgr;
Result.TextAlignment := _From.TextAlignment;
Result.DisplayFormat := _From.DisplayFormat;
Result.AutoSize := _From.AutoSize;
Result.Left := _From.Left;
Result.Width := _From.Width;
Result.Top := _From.Top;
Result.Font.Assign(_From.Font);
end;
function AddGroupToReport(aBreakName: String;
aDataPipeline:TppDataPipeline;
aReport: TppCustomReport; aHeight : Single): TppGroup;
{ the original is from digital-metaphors.public.reportbuilder.tech-tips
"Creating a Group in Code"}
var
lGroupBand: TppGroupBand;
begin
{add group to report}
Result := TppGroup(ppComponentCreate(aReport, TppGroup));
Result.Report := aReport;
Result.BreakName := aBreakName;
Result.DataPipeline := aDataPipeline;
{add footer band }
lGroupBand :=
TppGroupBand(ppComponentCreate(aReport,TppGroupFooterBand));
lGroupBand.Group := Result;
lGroupBand.Height := aHeight; // 2007-01-04 added (db)
end; {AddGroupToReport}
procedure TfoGrouByCode.FormShow(Sender: TObject);
begin
rgrCustNo := AddGroupToReport('CustNo',rp,rr,ppDetailBand1.Height+2);
AddCalcToGroup(rgrCustNo,rdAmountPaid);
AddCalcToGroup(rgrCustNo,rdAnz);
rr.Print;
Application.Terminate;
end;
end.
_________
--
Best regards
Dietmar Brueckmann
to find out how to do it, I've coded a sample-project based on a SELECT
over DBDEMOS.ORDERS.
Because needing sometime I'd like to share it with others.
If there's a place to store samples, I could send the .pas and .dfm.
_________
SELECT CustNo, OrderNo,
Sum(AmountPaid) AmountPaid, Count(*) Anz
FROM orders
Where CustNo <= 1351
Group By CustNo, OrderNo
Order By CustNo, OrderNo
_________
unit GroupByCodeFMU;
{
2007-01-04 Dietmar Brueckmann (db)
Tested on XP D6 rb9.03
Example-Form for "Creating a Group in Code" with Sum-Fields
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, Grids, DBGrids, DB, DBTables, ppCtrls, ppPrnabl, ppClass,
ppBands, ppCache, ppProd, ppReport, ppDB, ppComm, ppRelatv, ppDBPipe,
ppDBBDE, ppClasUt;
type
TfoGrouByCode = class(TForm)
DBGrid1: TDBGrid;
q: TQuery;
qCustNo: TFloatField;
qOrderNo: TFloatField;
qAmountPaid: TCurrencyField;
qAnz: TIntegerField;
sc: TDataSource;
rp: TppBDEPipeline;
rr: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppLabel1: TppLabel;
ppShape1: TppShape;
ppDBText1: TppDBText;
ppLabel2: TppLabel;
ppShape2: TppShape;
ppDBText2: TppDBText;
ppLabel3: TppLabel;
ppShape3: TppShape;
rdAmountPaid: TppDBText;
ppLabel4: TppLabel;
ppShape4: TppShape;
rdAnz: TppDBText;
rcAmountPaid: TppDBCalc;
ppDBCalc2: TppDBCalc;
ppSummaryBand1: TppSummaryBand;
procedure FormShow(Sender: TObject);
private
rgrCustNo : TppGroup;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
foGrouByCode: TfoGrouByCode;
implementation
{$R *.dfm}
function AddCalcToGroup(_rgr: TppGroup;_From: TppDBText): TppDBCalc;
begin
Result := TppDBCalc.Create(_rgr.Report);
Result.Name :=
Format('rc%s_%s',[_rgr.BreakName,_From.DataField]);
Result.DataField := _From.DataField;
Result.DataPipeline := _rgr.Report.DataPipeline;
Result.Band := _rgr.FooterBand;
Result.ResetGroup := _rgr;
Result.TextAlignment := _From.TextAlignment;
Result.DisplayFormat := _From.DisplayFormat;
Result.AutoSize := _From.AutoSize;
Result.Left := _From.Left;
Result.Width := _From.Width;
Result.Top := _From.Top;
Result.Font.Assign(_From.Font);
end;
function AddGroupToReport(aBreakName: String;
aDataPipeline:TppDataPipeline;
aReport: TppCustomReport; aHeight : Single): TppGroup;
{ the original is from digital-metaphors.public.reportbuilder.tech-tips
"Creating a Group in Code"}
var
lGroupBand: TppGroupBand;
begin
{add group to report}
Result := TppGroup(ppComponentCreate(aReport, TppGroup));
Result.Report := aReport;
Result.BreakName := aBreakName;
Result.DataPipeline := aDataPipeline;
{add footer band }
lGroupBand :=
TppGroupBand(ppComponentCreate(aReport,TppGroupFooterBand));
lGroupBand.Group := Result;
lGroupBand.Height := aHeight; // 2007-01-04 added (db)
end; {AddGroupToReport}
procedure TfoGrouByCode.FormShow(Sender: TObject);
begin
rgrCustNo := AddGroupToReport('CustNo',rp,rr,ppDetailBand1.Height+2);
AddCalcToGroup(rgrCustNo,rdAmountPaid);
AddCalcToGroup(rgrCustNo,rdAnz);
rr.Print;
Application.Terminate;
end;
end.
_________
--
Best regards
Dietmar Brueckmann
This discussion has been closed.
Comments
Thanks for the example. If you would like to send it to us, we will keep it
in our archives.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com