用过reportbuilder报表的朋友请帮忙!小问题一个,谢谢! (20分)

  • 主题发起人 主题发起人 winsock
  • 开始时间 开始时间
W

winsock

Unregistered / Unconfirmed
GUEST, unregistred user!
请教一下!在reportbuilder中,怎么把ppDBCalc1(汇总框)的数值赋于一个label呢?
pplabel1.Caption:=ppdbcalc1.value?为什么会返回的结果为要汇总字段的第一条记录呢?
还有,代码我是写在HeaderBeforPrint事件里面。ppLabel1里面的ongettext事件也试了!
代码窗口也试了!可返回的值只是此字段第一条记录的值!而不是此字段的汇总!
为什么呀?
 
代碼寫看什麼地方?是ppLabel1的onPrint事件嗎?另代碼在預覽時
不會執行,要看結果應用打印機的預覽功能或打印出來...
 
应该不能写在onPrint事件里面呀!报错!
我是写在HeaderBeforPrint事件里面。ppLabel1里面的ongettext事件里面!代码窗口也写了!
可返回的值只是此字段第一条记录的值!而不是此字段的汇总!为什么呀?
 
你的報表有打印出來看嗎?
 
有呀!或许代码应该不可以那样写吧!在帮我看看吧!老兄!
 
對了,別忘了數據類型轉換...
 
我測試通過:
資料:
if exists (select * from sysobjects where id = OBJECT_ID('[t3]') and OBJECTPROPERTY(id, 'IsUserTable') = 1) DROP TABLE [t3]
CREATE TABLE [t3] ( [dm] [char] (2) NULL , [je] [int] NULL )
INSERT [t3] ( [dm] , [je] ) VALUES ( '01' , 100 )
INSERT [t3] ( [dm] , [je] ) VALUES ( '02' , 200 )
INSERT [t3] ( [dm] , [je] ) VALUES ( '01' , 150 )
INSERT [t3] ( [dm] , [je] ) VALUES ( '03' , 100 )
INSERT [t3] ( [dm] , [je] ) VALUES ( '04' , 150 )
文件:Unit1.dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 40
Top = 176
Width = 521
Height = 233
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 464
Top = 88
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object ppReport1: TppReport
AutoStop = False
DataPipeline = ppDBPipeline1
PrinterSetup.BinName = 'Default'
PrinterSetup.DocumentName = 'Report'
PrinterSetup.PaperName = 'Letter'
PrinterSetup.PrinterName = 'Default'
PrinterSetup.mmMarginBottom = 6350
PrinterSetup.mmMarginLeft = 6350
PrinterSetup.mmMarginRight = 6350
PrinterSetup.mmMarginTop = 6350
PrinterSetup.mmPaperHeight = 279401
PrinterSetup.mmPaperWidth = 215900
PrinterSetup.PaperSize = 1
DeviceType = 'Screen'
Left = 320
Top = 96
Version = '6.03'
mmColumnWidth = 0
DataPipelineName = 'ppDBPipeline1'
object ppHeaderBand1: TppHeaderBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
end
object ppDetailBand1: TppDetailBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
end
object ppFooterBand1: TppFooterBand
mmBottomOffset = 0
mmHeight = 13229
mmPrintPosition = 0
object ppDBCalc1: TppDBCalc
UserName = 'DBCalc1'
DataField = 'je'
DataPipeline = ppDBPipeline1
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Name = 'Arial'
Font.Size = 10
Font.Style = []
Transparent = True
DataPipelineName = 'ppDBPipeline1'
mmHeight = 3969
mmLeft = 49213
mmTop = 2381
mmWidth = 17198
BandType = 8
end
object ppLabel1: TppLabel
OnPrint = ppLabel1Print
UserName = 'Label1'
Caption = 'Label1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Name = 'Arial'
Font.Size = 10
Font.Style = []
Transparent = True
mmHeight = 3969
mmLeft = 75142
mmTop = 2910
mmWidth = 10583
BandType = 8
end
end
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Password=jserp;Persist Security Info=True;Us' +
'er ID=jserp;Initial Catalog=test;Data Source=BILL'
LoginPrompt = False
Provider = 'SQLOLEDB.1'
Left = 128
Top = 56
end
object ADOTable1: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = 't3'
Left = 208
Top = 48
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 264
Top = 64
end
object ppDBPipeline1: TppDBPipeline
DataSource = DataSource1
UserName = 'DBPipeline1'
Left = 384
Top = 88
object ppDBPipeline1ppField1: TppField
FieldAlias = 'dm'
FieldName = 'dm'
FieldLength = 2
DisplayWidth = 2
Position = 0
end
object ppDBPipeline1ppField2: TppField
Alignment = taRightJustify
FieldAlias = 'je'
FieldName = 'je'
FieldLength = 0
DataType = dtInteger
DisplayWidth = 10
Position = 1
end
end
end
文件:Unit1.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ppDB, ppDBPipe, Grids, DBGrids, DB, ADODB, ppCtrls, ppPrnabl,
ppClass, ppBands, ppCache, ppComm, ppRelatv, ppProd, ppReport, StdCtrls;
type
TForm1 = class(TForm)
ppReport1: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppFooterBand1: TppFooterBand;
ppLabel1: TppLabel;
ppDBCalc1: TppDBCalc;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ppDBPipeline1: TppDBPipeline;
Button1: TButton;
procedure ppLabel1Print(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ppLabel1Print(Sender: TObject);
begin
Self.ppLabel1.Caption:=ppDBCalc1.Value;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Self.ppReport1.Print;
end;

end.

注:pplabel1及ppdbcalc1均放在footer區,一卻正常
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
466
import
I
后退
顶部