我自己用的,绝对管用 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 widelen do begin if length(temparr[j-1])+length(s[i])>wide then begin j:=j+1; setlength(temparr,j); temparr[j-1]:=s[i]; end else begin temparr[j-1]:=temparr[j-1]+s[i]; end; end; s:=''; for i:=0 to length(temparr)-2 do s:=s+temparr[i]+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;
只有添加換行符了 看看有用沒 function PrtString(prtCount: integer;var s:string): string; var sLine: string; iCutLength: integer; begin sLine :=s; s:=''; iCutLength:=prtCount; repeat while (bytetype(sLine,iCutLength)<>mbTrailByte) do Dec(iCutLength); s:=s+Copy(sLine, 1, iCutLength)+#10#13; sLine := Copy(sLine, iCutLength + 1, Length(sLine) - iCutLength); iCutLength:=prtCount; until Length(trim(sLine)) <= 0; end;
前提是AutoSize := False;
AutoStretch := True;
WordWrap := True;
AutoStretch := True;
WordWrap := True;
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 widelen do
begin
if length(temparr[j-1])+length(s[i])>wide then
begin
j:=j+1;
setlength(temparr,j);
temparr[j-1]:=s[i];
end
else
begin
temparr[j-1]:=temparr[j-1]+s[i];
end;
end;
s:='';
for i:=0 to length(temparr)-2 do
s:=s+temparr[i]+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;
看看有用沒
function PrtString(prtCount: integer;var s:string): string;
var
sLine: string;
iCutLength: integer;
begin
sLine :=s;
s:='';
iCutLength:=prtCount;
repeat
while (bytetype(sLine,iCutLength)<>mbTrailByte) do Dec(iCutLength);
s:=s+Copy(sLine, 1, iCutLength)+#10#13;
sLine := Copy(sLine, iCutLength + 1, Length(sLine) - iCutLength);
iCutLength:=prtCount;
until Length(trim(sLine)) <= 0;
end;