QReport的动态报表问题?(100分)

  • 主题发起人 主题发起人 zdt
  • 开始时间 开始时间
Z

zdt

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFEntrust.BitBtn7Click(Sender: TObject);
var
QRLaList:Array of TQRLabel;
QRTeList:Array of TQRDBText;
Count,i,k:integer;
begin
FPRINT.QuickRep1.DataSet:=Query;
Count:=Query.FieldCount;
SetLength(QRLaList,Count);
SetLength(QRTeList,Count);
for i:=0 to high(QRTeList)do
begin
k:=0;
QRLaList:=TQRLabel.Create(Self);
if i=0 then
QRLaList.Left:=0
else
QRLaList.Left:=QRLaList[i-1].Left+QRLaList[i-1].Width+12;
QRLaList.Parent:=FPRINT.QRBand1;
QRLaList.AutoSize:=false;
Query.First;
While not Query.Eofdo
begin
if Query.Fields.dataSize>k then
k:=Query.Fields.DataSize;
Query.Next;
end;
QRLaList.Caption:=Query.Recordset.Fields.Name;
QRLaList.Top:=10;
if Query.FieldCount>12 then
begin
QRLaList.Font.Size:=7;
QRLaList.Width:=k*2+5;
end
else
begin
QRLaList.Font.Size:=8;
QRLaList.Width:=K*3+5;
end;
QRTeList:=TQRDBText.Create(Self);
QRTeList.Parent:=FPRINT.DetailBand1;
QRTeList.DataSet:=Query;
QRTeList.DataField:=Query.Recordset.Fields.Name;
QRTeList.AutoSize:=True;
QRTeList.Font.Size:=QRLaList.Font.Size;
QRTeList.Top:=10;
QRTeList.Left:=QRLaList.Left;
end;
FPRINT.QuickRep1.Preview;
for i:=0 to count-1do
begin
FPRINT.DetailBand1.RemoveControl(QRTeList);
FPRINT.QRBand1.RemoveControl(QRLaList);
end;
end;

问题是如果前一个字段太长,后一个字段会把前一个字段盖住,怎么解决???
先谢谢大家了!!!
 
没耐心看完,随便说两句
QRLaList:=TQRLabel.Create(Self);
在上一句之后是不是要有一句
QRLaList.autosize:=false;呢
否则这一句会不会失效QRLaList.Width:=K*3+5;
我没DELPHI试不起来
 
可使各字段内容自动换行,同时调整band高度
 
如果要得出一个字段最大的宽度我想还是用SQL为好吧,用循环比较可能比较慢
select max(length(yourfield)) from table
然后将这个字段值取出来用canvas.textwidth算出宽度再赋给qrdbtext的宽度
 
52free,你说的length,SQL并不认识这个函数,而且我打的东西不能换行
 
哦,那你看看帮助有没有求字段值长度的函数
而且我打的东西不能换行//不能理解你是指什么
 
关于打印换行,我也试了其他控件,效果都不太理想,不是出现乱码就是第二行出现重复。
后来经过自己实验,终于搞定了,下面贴出源码,与大家共享:
关键是处理qrdbtext的onprint事件,用下面的代码代替即可。
const
MAXLEN=40;//可控制每行的宽度
var
i_ins,i,j:integer;
begin
i_ins:=0;
j:=length(value) div MAXLEN;
for i:=1 to jdo
begin
if Windows.IsDBCSLeadByte(byte(value[i*MAXLEN-1+i_ins])) and Windows.IsDBCSLeadByte(byte(value[i*MAXLEN+i_ins])) then
begin
insert(#13,value,i*MAXLEN+1+i_ins);
inc(i_ins);
end
else
begin
insert(#13,value,i*MAXLEN+i_ins);
inc(i_ins);
end;
end;
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QuickRpt, QRCtrls, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
QuickRep1: TQuickRep;
TitleBand1: TQRBand;
QRLabel1: TQRLabel;
Button1: TButton;
procedure QRLabel1Print(sender: TObject;
var Value: string);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.QRLabel1Print(sender: TObject;
var Value: string);
var
str: widestring;
nowstr: string;
i: integer;
begin
self.Font := TQRLabel(sender).Font;
str := Value;
Value := '';
nowstr := '';
for i := 1 to length(str)do
begin
if Canvas.TextWidth(nowstr + str) > TQRLabel(sender).Width then
begin
nowstr := '';
Value := Value + #13;
nowstr := nowstr + str;
Value := Value + str;
end
else
begin
nowstr := nowstr + str;
Value := Value + str;
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
QuickRep1.Preview;
end;

end.

 
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Scaled = False
PixelsPerInch = 96
TextHeight = 13
object QuickRep1: TQuickRep
Left = 160
Top = 32
Width = 794
Height = 1123
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Functions.Strings = (
'PAGENUMBER'
'COLUMNNUMBER'
'REPORTTITLE')
Functions.DATA = (
'0'
'0'
'''''')
Options = [FirstPageHeader, LastPageFooter]
Page.Columns = 1
Page.Orientation = poPortrait
Page.PaperSize = A4
Page.Values = (
100
2970
100
2100
100
100
0)
PrinterSettings.Copies = 1
PrinterSettings.Duplex = False
PrinterSettings.FirstPage = 0
PrinterSettings.LastPage = 0
PrinterSettings.OutputBin = Auto
PrintIfEmpty = True
SnapToGrid = True
Units = MM
Zoom = 100
object TitleBand1: TQRBand
Left = 38
Top = 38
Width = 718
Height = 203
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
537.104166666667
1899.70833333333)
BandType = rbTitle
object QRLabel1: TQRLabel
Left = 32
Top = 0
Width = 89
Height = 185
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
489.479166666667
84.6666666666667
0
235.479166666667)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = False
AutoStretch = False
Caption =
'QRLabel1QRLabel1QRLabel1QRLabel1QRLabel1QRLabel1QRLabel1QRLabel1' +
'QRLabel1QR哈哈哈哈哈哈哈哈哈哈Label1'
Color = clWhite
OnPrint = QRLabel1Print
Transparent = False
WordWrap = True
FontSize = 10
end
end
end
object Button1: TButton
Left = 40
Top = 32
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
 
RM_Pgopt.pas
 
多人接受答案了。
 
后退
顶部