D6 的 QReport QRDBText不能自动换行,WordWrap不起作用。(50分)

  • 主题发起人 主题发起人 斗士
  • 开始时间 开始时间

斗士

Unregistered / Unconfirmed
GUEST, unregistred user!
用了许多报表控件,ReportBuilder FaseReport
对中文支持不好,换行就乱码。
想试试QuickReport,这可是Borland的官方控件,D6自带的,
可惜QRDBText不能自动换行,WordWrap不起作用,
网上下了QReport3.6.2,也不行。
 
use report machine
www.pcjingning.com
 
转贴:
有众多高手的指点,我的FR2.46安装很顺利。包括改菜单字体、编译中文资源、汉字折行。关于汉字折行,这里贴出对WrapLine函数的完整修改,以供参考。

procedure WrapLine(const s: WideString);
var
i, cur, beg, last, LoopPos: Integer;
WasBreak, CRLF: Boolean;
Dest1, Dest2, Dest3, Dest4: PWideChar;

function Is1013(wc:WideChar): boolean;
begin
GetMem(Dest1,2);
GetMem(Dest2,2);
try
StringToWideChar(#10,Dest1,2);
StringToWideChar(#13,Dest2,2);
Result := (wc=Dest1^) or (wc=Dest2^);
finally
FreeMem(Dest1);
FreeMem(Dest2);
end;
end;

function GIsSpace(wc:WideChar): boolean;
begin
GetMem(Dest1,2);
GetMem(Dest2,2);
GetMem(Dest3,2);
GetMem(Dest4,2);
try
StringToWideChar(' ',Dest1,2);
StringToWideChar('.',Dest2,2);
StringToWideChar(',',Dest3,2);
StringToWideChar('-',Dest4,2);
Result := (wc=Dest1^) or (wc=Dest2^) or (wc=Dest3^) or (wc=Dest4^) ;
finally
FreeMem(Dest1);
FreeMem(Dest2);
FreeMem(Dest3);
FreeMem(Dest4);
end;
end;

begin
CRLF := False;
LoopPos := 0;
for i := 1 to Length(s)do
//if s in [#10, #13] then
//original
if Is1013(s) then
begin
CRLF := True;
break;
end;
last := 1;
beg := 1;
if not CRLF and ((Length(s) <= 1) or (WCanvas.TextWidth(s) <= maxwidth)) then
OutLine(s + #1)
else
begin
cur := 1;
while cur <= Length(s)do
begin
if Is1013(s[cur]) then
begin
OutLine(Copy(s, beg, cur - beg) + #1);
while (cur < Length(s)) and Is1013(s[cur])do
Inc(cur);
beg := cur;
last := beg;
if Is1013(s[cur]) then
Exit else
continue;
end;
if s[cur] <> ' ' then
if WCanvas.TextWidth(Copy(s, beg, cur - beg + 1)) > maxwidth then
begin
WasBreak := False;
if (Flags and flWordBreak) <> 0 then
begin
i := cur;
while (i <= Length(s)) and not GIsSpace(s)do
Inc(i);
b := BreakWord(Copy(s, last + 1, i - last - 1));
if Length(b) > 0 then
begin
i := 1;
cur := last;
while (i <= Length(b)) and
(WCanvas.TextWidth(Copy(s, beg, last - beg + 1 + Ord(b)) + '-') <= maxwidth)do
begin
WasBreak := True;
cur := last + Ord(b);
Inc(i);
end;
last := cur;
end;
end
else
if last = beg then
last := cur;
if WasBreak then
OutLine(Copy(s, beg, last - beg + 1) + '-')
else
if s[last] = ' ' then
OutLine(Copy(s, beg, last - beg)) else
begin
OutLine(Copy(s, beg, last - beg));
Dec(last);
end;
if ((Flags and flWordBreak) <> 0) and not WasBreak and (last = cur - 1) then
if LoopPos = cur then
begin
beg := cur + 1;
cur := Length(s);
break;
end
else
LoopPos := cur;
beg := last + 1;
last := beg;
end;
// if s[cur] in spaces then
last := cur;
if s[cur] = ' ' then
last := cur;
Inc(cur);
end;
if beg <> cur then
OutLine(Copy(s, beg, cur - beg + 1) + #1);
end;
end;
 
to y2ky2k
有没有解决Report Builder 中文换行乱码的办法。
 
QREPORT最好里不要用QRDBTEXT,用QRLABEL吧.
在NEEDDATA事件给QRLABEL赋值...
 
我试了,还是不能换行。
 
使用TQRRichText可以自动换行
 
procedure autochangerow(wide: integer;
var value: string);
var
temparr:array of string;
widelen,i,j:integer;
s:widestring;
begin
j:=1;
s:=value;
widelen:=length(s);
setlength(temparr,j);
temparr[0]:='';
for i:=1 to widelendo
begin
if length(temparr[j-1])+length(s)>wide then
begin
j:=j+1;
setlength(temparr,j);
temparr[j-1]:=s;
end
else
begin
temparr[j-1]:=temparr[j-1]+s;
end;
end;
s:='';
for i:=0 to length(temparr)-2do
s:=s+temparr+chr(13);
value:=s+temparr[length(temparr)-1];
temparr:=nil;
end;

在QRDBText的ONPRINT事件中写如下代码
procedure Tshaminputrptform.qrdbtxt_namePrint(sender: TObject;
var Value: String);
begin
autochangerow(39,value);
end;
函数中WIDE参数为一行长度,汉字不会乱码
 
TQRDBRichText可以换行,但却连不到数据。
 
什么意思
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部