procedure TmainFormPrintBtnClick(Sender : TObject) begin repForm.Qrep1.Print; end; 2.HeadBand1、DetailBand1及ChildBand1的BeforePrint事件 procedure TrepForm.HeadBand1BeforePrint(Sender : TQRCustomBand; Var PrintBand : Boolean) Begin Shape1.Height:=HeadBand1.Height; Shape2.Height:=HeadBand1.Height; Shape3.Height:=HeadBand1.Height; End;
procedure TrepForm.DetailBand1BeforePrint(Sender : TQRCustomBand; Var PrintBand : Boolean) begin PrintBand:=bh$#@60; $#@62;Query1[‘dlbh’]; if PrintBand then begin bh:=Query1[‘dlbh’]; Shape4.Height:=DetailBand1.Height; Shape5.Height:=DetailBand1.Height; Shape6.Height:=DetailBand1.Height; end end;
procedure TrepForm.ChildBand1BeforePrint(Sender : TQRCustomBand; Var PrintBand : Boolean) Begin Shape7.Height:=ChildBand1.Height; Shape8.Height:=ChildBand1.Height; Shape9.Height:=ChildBand1.Height; End; bh應在變量定義部分定義: Var bh : shortint=0; 幾個TQRShape部件的高度(Height)與所在TQRBand 部件保持一致,使豎線打印得整潔。假如在設計階段調整了TQRBand部件的高度,也不會出現豎線斷線或過長的情況。 在DetailBand1的BeforePrint事件中用PrintBand進行控制,可使每個設備大類名稱只需打印一次,而不是每個型號都對應打印一次大類名稱。因為dlbh字段的值都大于0,bh初值設為0使它與任一記錄的dlbh字段的值都不同,以確保第一個大類名稱被打印。這樣就生成了一個從多個數據表中提取數據,并帶有表格線的數據報表。 注:本例工程文件為sbgl.dpr,原程序文件為main.pas和sbrep.pas,若要測試請將dlbmk.dbf、sbxhk.dbf、bmsbk.dbf三個文件放在d:/sb目錄下。