我给你个Demo,你试试看:
var
i : integer;
Rep : TQuickReport;
QRDesignBandTitle, QRDesignBandDetail, QRDesignBandFooter: TQRBand;
QRDesignLabelTitle, QRDesignLabelFooter: TQRLabel;
QRDesignDBText1, QRDesignDBText2: TQRDBText;
QRDesignDBTextFooter : TQRDBText;
begin
for i := 0 to Form.ComponentCount-1do
begin
if Form.Components.ClassName='TQuickReport' then
begin
Rep := TQuickReport(Form.Components);
with Repdo
begin
Rep.DataSet := Table1;
//==========Title=================================
QRDesignBandTitle := TQRBand.Create(Rep);
QRDesignBandTitle.BandType := rbTitle;
//定義Band型態
QRDesignBandTitle.Height := 100;
//定義Band高度
QRDesignBandTitle.Color := clYellow;
//定義Band顏色
QRDesignBandTitle.Parent := Rep;
//定義Band父代,注意這個屬性一定要設
Rep.AddBand(QRDesignBandTitle);
QRDesignLabelTitle := TQRLabel.Create(QRDesignBandTitle);
QRDesignLabelTitle.Caption := 'Create Form Delphi';
QRDesignLabelTitle.Font.Size := 16;
//定義Label字型
QRDesignLabelTitle.Top := 10;
QRDesignLabelTitle.Left := 50;
QRDesignLabelTitle.Parent := QRDesignBandTitle;
//==========Detail=================================
QRDesignBandDetail := TQRBand.Create(Rep);
QRDesignBandDetail.BandType := rbDetail;
QRDesignBandDetail.Parent := Rep;
Rep.AddBand(QRDesignBandDetail);
QRDesignDBText1 := TQRDBText.Create(QRDesignBandDetail);
QRDesignDBText1.DataSet := AcroTable1;
QRDesignDBText1.DataField := 'SERIALNO';
QRDesignDBText1.Top := 10;
QRDesignDBText1.Left := 10;
QRDesignDBText1.Parent := QRDesignBandDetail;
QRDesignDBText2 := TQRDBText.Create(QRDesignBandDetail);
QRDesignDBText2.DataSet := AcroTable1;
QRDesignDBText2.DataField := 'PROGRAMNAME';
QRDesignDBText2.Top := 10;
QRDesignDBText2.Left := 100;
QRDesignDBText2.Parent := QRDesignBandDetail;
//==========Footer=================================
QRDesignBandFooter := TQRBand.Create(Rep);
QRDesignBandFooter.BandType := rbPageFooter;
//定義Band型態
QRDesignBandFooter.Height := 50;
//定義Band高度
QRDesignBandFooter.Color := clSilver;
//定義Band顏色
QRDesignBandFooter.Parent := Rep;
//定義Band父代,注意這個屬性一定要設
Rep.AddBand(QRDesignBandFooter);
QRDesignLabelFooter := TQRLabel.Create(QRDesignBandFooter);
QRDesignLabelFooter.Caption := 'Footer';
QRDesignLabelFooter.Font.Size := 16;
//定義Label字型
QRDesignLabelFooter.Top := 10;
QRDesignLabelFooter.Left := 50;
QRDesignLabelFooter.Parent := QRDesignBandFooter;
QRDesignDBTextFooter := TQRDBText.Create(QRDesignBandFooter);
QRDesignDBTextFooter.DataSet := AcroTable1;
QRDesignDBTextFooter.DataField := 'PROGRAMNAME';
QRDesignDBTextFooter.Font.Size := 16;
//定義Label字型
QRDesignDBTextFooter.Top := 10;
QRDesignDBTextFooter.Left := 250;
QRDesignDBTextFooter.Parent := QRDesignBandFooter;
end;
end;
end;
end;