QuickRep做報表換行問題。急需您的幫助! (100分)

hongxing_dl兄:
我來啦。你發給我的沒有附件呀!你上QQ呀,在QQ上幫我!
lyq2276959高手
  謝謝你啦,等我調試完後再給你分。
   
 
哦——没有附件呀————???
那我重新发——————————
 
是呀,沒有附件。我等會再去看看!還沒有收到
 
>sail_world
>weifang
邮件全部发出了
 
hongxing_dl兄:
你好厲害!我收到啦,等會再結貼給你分!如果還有什麼問題,我再請教你! 真的謝謝你!
 
hongxing_dl兄:
我怎樣安裝你發給我的QRtext呀?
 
我安裝不上,快告訴我怎麼做?
 
1、把qrtext.pas打开,然后install component->选择包(可以insert new package),然后编译(compile/install)
2、
新建一个包(package),然后 add 选择这个qrtext.pas,install就可以了。
 
我不知道怎樣新建一个包(package)?快幫我呀!
 
哎——看来我真的上qq了
 
是呀,你快上來,我怎麼會安裝不上呢?
 
>>>>lyq2276959
这个问题解决了还得谢谢你老兄啊
看看下面的代码,多亏老兄的qrtext,我作个修改(一点点,自动适应高度的)
加了个alignment属性
layout属性还没来得及写。
还准备加上dataset和datafield属性,就相当于qrdbtext的升级版
//---------------------------------------------------------------------------
//控 件 包:Quickreport附加控件
//控件名称:QrText
//控件作者:along(阿龙)
//Eamil :longyunqiang@163.com;
longyunqiang@163.net
//发布类型:免费控件
//最后更新:2003.10.29
//---------------------------------------------------------------------------
// 主要功能:
// 改进了QRlabel的换行,可实现文字自动换行,且可设置行间距。
//---------------------------------------------------------------------------
//使用:使用方法与Quickreport的QRlabel相似。
//主要属性:
// text:要打印的文字内容。
// linespace:行间距(单位:点)。
//---------------------------------------------------------------------------
unit QRtext;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Graphics, QuickRpt;
type
TLayout = (tlTop, tlCenter, tlBottom);
TQRtext = class(tqrprintable)
private
Ftext: string;
//要显示的内容(内部用的变量)
Flinespace: integer;
//行间距(内部用的变量)
Fcount: integer;
FAlignment: TAlignment;
FLayOut: TLayOut;
//一行中的字数
procedure setftext(value: string);
//显示内容(将属性表的数据给内容变量)
procedure setFlinespace(value: integer);
//设置行间距(将属性表的数据给行间距变量)
function FormatLine(const oldLine: string;
const LineLength: integer): string;
procedure SetAlignments(const Value: TAlignment);
procedure SetLayOut(const Value: TLayOut);
//分行函数
{ Private declarations }
protected
procedure Paint;
override;
//显示数据
procedure Print(OfsX, OfsY: integer);
override;
//打印数据
{ Protected declarations }
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
{ Public declarations }
published
property text: string read Ftext write setftext;
//显示内容(将属性表的数据)
property linespace: integer read Flinespace write setFlinespace;
//设置行间距(将属性表的数据)
property font;
//设置字体
//////////////////////////by hongxing_dl
property Align;
property Alignment:TAlignment read FAlignment write SetAlignments;
property LayOut :TLayOut read FLayOut write SetLayOut;
{ Published declarations }
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('QReport', [TQRtext]);
end;

{ TQRtext }
constructor TQRtext.Create(AOwner: TComponent);
begin
inherited;
width := 30;
height := 20;
Ftext := 'Text';
font.Name := '宋体';
font.Size := 10;
FAlignment:=taLeftJustify;
end;

destructor TQRtext.Destroy;
begin
inherited;
end;

procedure TQRtext.Paint;
var
list1, list2: Tstrings;
i, y, sleft,fontheight: integer;
begin
inherited;
//执行父类的动作。画边框
//清除显示
canvas.Brush.Style := bssolid;
canvas.Brush.Color := clwhite;
canvas.FillRect(canvas.ClipRect);
if length(Ftext) <= 0 then
exit;
//无字符要显示则退出
canvas.Font := font;
fontheight := canvas.TextHeight('字');
//求得每行高度
Fcount := width div canvas.TextWidth('字');
//求得每行字数
list1 := Tstringlist.create;
//用于分行
list2 := Tstringlist.create;
//用于显示
list1.Text := text;
//先处理手工分行的字符。
//然后再对每一行进行自动分行。
for i := 0 to list1.Count - 1do
list2.Text := list2.Text + formatline(list1.Strings, fcount * 2);
//处理显示
//modified by hongxing_dl (0->2)
y := 2;
sleft:=2;
for i := 0 to list2.Count - 1do
begin
case FAlignment of
taLeftJustify : sleft:=2;
taRightJustify: sleft:=width - canvas.TextWidth(list2.Strings);
taCenter : sleft:=(width - canvas.TextWidth(list2.Strings)) div 2;
end;
canvas.TextOut(sleft, y, list2.Strings);
//显示字符
y := y + fontheight + Flinespace;
//下一行的位置=上一行的位置+字高+行间距
end;

list1.Free;
list2.Free;
height := y;
end;

procedure TQRtext.print(OfsX, OfsY: integer);
var
list1, list2: Tstrings;
i, y, sleft,fontheight: integer;
begin
inherited;
//执行父类的动作。画边框
with qrprinterdo
begin
if length(Ftext) = 0 then
Ftext := ' ';
canvas.Font := font;
fontheight := canvas.TextHeight('字');
//求得每行高度
Fcount := width div canvas.TextWidth('字');
//求得每行字数
list1 := Tstringlist.create;
//用于分行
list2 := Tstringlist.create;
//用于显示
list1.Text := text;
//先处理手工分行的字符。
//然后再对每一行进行自动分行。
for i := 0 to list1.Count - 1do
list2.Text := list2.Text + formatline(list1.Strings, fcount * 2);
//处理显示
y := 2+ypos(size.Top + ofsy);
sleft:=2;
for i := 0 to list2.Count - 1do
begin
case FAlignment of
taLeftJustify : sleft:=2;
taRightJustify: sleft:=width - canvas.TextWidth(list2.Strings);
taCenter : sleft:=(width - canvas.TextWidth(list2.Strings)) div 2;
end;
canvas.TextOut(sleft+xpos(size.left + ofsx), y, list2.Strings);
//显示字符
y := y + fontheight + Flinespace;
//下一行的位置=上一行的位置+字高+行间距
end;
end;

list1.Free;
list2.Free;
end;

procedure TQRtext.setFlinespace(value: integer);
begin
Flinespace := value;
paint;
//值改变后重新显示数据
end;

procedure TQRtext.setftext(value: string);
begin
if Ftext <> value then
begin
Ftext := value;
paint;
//值改变后重新显示数据
end;
end;

function TQRtext.FormatLine(const oldLine: string;
const LineLength: integer): string;
var
Line: string;
NewLine, ReturnLine: string;
cnumber, number, theLength, j: integer;
begin
line := oldLine;
NewLine := '';
ReturnLine := '';
cnumber := 0;
number := 0;
theLength := Length(line);
j := 1;
while (j <= theLength)do
begin
if (LineLength <= number) then
//需要分行了
begin
if ((j > 1) and (line[j - 1] < #$80) and (line[j] < #$80)) then
//这个判断不适合big5码
begin
//前面一个与现在字符都不是中文字符
if (line[j - 1] = ' ') then
begin
if (line[j] <> ' ') then
begin
ReturnLine := ReturnLine + NewLine + #13#10;
NewLine := line[j];
number := 1;
cnumber := 0;
Inc(j);
continue;
end
else
begin
Inc(j);
continue;
end;
end
else
begin
//前面一个字符是英文,现在的字符也是英文或空格,不分段
NewLine := NewLine + line[j];
cnumber := 0;
Inc(j);
continue;
end;
end
else
if (0 = (cnumber mod 2)) then
//有个什么函数可以直接判断的来着
begin
ReturnLine := ReturnLine + NewLine + #13#10;
NewLine := line[j];
number := 1;
if (line[j] >= #$80) then
cnumber := 1;
Inc(j);
continue;
end
else
begin
//是中文字符的后半个字符
NewLine := NewLine + line[j];
cnumber := 0;
Inc(j);
continue;
end;
end
else
//长度小于等于LineLength
begin
NewLine := NewLine + line[j];
if (line[j] >= #$80) then
begin
Inc(cnumber);
Inc(number);
end
else
begin
Inc(number);
cnumber := 0;
if (j < theLength) and (line[j + 1] >= #$80) and (1 = number mod 2) then
begin
//如果下一个是中文,而现在为奇数,则补一个空格
NewLine := NewLine + ' ';
Inc(number);
end;
end;
Inc(j);
continue;
end;
end;
ReturnLine := ReturnLine + NewLine + #13#10;
Result := ReturnLine;
end;

procedure TQRtext.SetAlignments(const Value: TAlignment);
begin
if FAlignment<>Value then
begin
FAlignment := Value;
Self.Refresh;
end;
end;

procedure TQRtext.SetLayOut(const Value: TLayOut);
begin
if FLayOut<>Value then
begin
FLayOut := Value;
Self.Refresh;
end;
end;

end.
 
盡管還沒有很好的解決!結貼啦。謝謝各位
 
顶部