本人给你一段代码
1. Declare the necessary uses clause.
uses
DB, {contains TDataSource}
DBTables, {contains TTable}
ppReport, {contains TppReport}
ppDBBDE, {contains TppBDEPipeline}
ppBands, {contains all band classes}
ppCtrls, {contains standard components}
ppTypes, {contains all ReportBuilder enumerated types}
ppVar;
{contains SystemVariable and Variable classes}
2. Declare the local variables necessary to create the report.
procedure TForm1.Button1Click(Sender: TObject);
var
lTable: TTable;
lDataSource: TDataSource;
lDataPipeline: TppBDEPipeline;
lReport: TppReport;
lLabel1: TppLabel;
lLabel2: TppLabel;
lDBText1: TppDBText;
lDBText2: TppDBText;
lSysVar: TppSystemVariable;
3. Create data access components.
lTable := TTable.Create(Self);
lTable.Name := 'tblCustomer';
lTable.DatabaseName := 'DBDemos';
lTable.TableName := 'customer.db';
lDataSource := TDataSource.Create(Self);
lDataSource.Name := 'dsCustomer';
lDataSource.DataSet := lTable;
lDataPipeline := TppBDEPipeline.Create(Self);
lDataPipeline.Name := 'plCustomer';
lDataPipeline.DataSource := lDataSource;
4. Create the report.
lReport := TppReport.Create(Self);
lReport.DataPipeline := lDataPipeline;
5. Create the report bands.
lReport.CreateDefaultBands;
6. Add labels to the header band.
lLabel1 := TppLabel.Create(Self);
lLabel1.Band := lReport.HeaderBand;
lLabel1.spLeft := 2;
lLabel1.spTop := 2;
lLabel1.Caption := 'Customer No.';
lLabel2 := TppLabel.Create(Self);
lLabel2.Band := lReport.HeaderBand;
lLabel2.spLeft := lLabel1.spLeft + lLabel1.spWidth + 3;
lLabel2.spTop := 2;
lLabel2.Caption := 'Company Name';
7. Add data-aware components to the detail band.
lDBText1 := TppDBText.Create(Self);
lDBText1.Band := lReport.DetailBand;
lDBText1.spLeft := lLabel1.spLeft;
lDBText1.spTop := lLabel1.spTop;
lDBText1.DataPipeline := lDataPipeline;
lDBText1.DataField := 'CustNo';
lDBText2 := TppDBText.Create(Self);
lDBText2.Band := lReport.DetailBand;
lDBText2.spLeft := lLabel2.spLeft;
lDBText2.spTop := lLabel2.spTop;
lDBText2.DataPipeline := lDataPipeline;
lDBText2.DataField := 'Company';
9. Preview the report.
lReport.Print;
10. Free the report.
lReport.Free;
11. Free the data access components.
lTable.Free;
lDataSource.Free;
lDataPipeline.Free;