Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and have got an error. The final part of the text was not wrapped.
Ant?nio

Mailing lists / lazarus / 2010-10
13 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and have got an error. The final part of the text was not wrapped.
Ant?nio
06.10.2010 16:09, Ant?nio ?????:
Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and have got an error. The final part of the text was not wrapped.
Please make a bug report and attach test project to it.
Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and…
Ant?nio wroteIs there any length limit to WrapText function?
No there shouldn't be.
Also, please always say which fpc, lazarus and operating systems versions you are using in posts about problems.
thanks,
Lazarus 0.9.29 r24105 FPC 2.4.0 i386-win32-win32/win64 Windows XP
Ant?nio
2010/10/7 Felipe Monteiro de Carvalho :
You could try updating to the latest rev. We are already at rev27595
If it doesn't work, then I recommend Maxim's instructions. A bug report + test project
For me wordwrap always worked.
I have found the Delphi function, which does not work fine also. It is:
function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet;
MaxCol: Integer): string;
const
QuoteChars = ['''', '"'];
var
Col, Pos: Integer;
LinePos, LineLen: Integer;
BreakLen, BreakPos: Integer;
QuoteChar, CurChar: Char;
ExistingBreak: Boolean;
L: Integer;
begin
Col := 1;
Pos := 1;
LinePos := 1;
BreakPos := 0;
QuoteChar := #0;
ExistingBreak := False;
LineLen := Length(Line);
BreakLen := Length(BreakStr);
Result := '';
while Pos <= LineLen do
begin
CurChar := Line[Pos];
if CurChar in LeadBytes then
begin
L := CharLength(Line, Pos) - 1;
Inc(Pos, L);
Inc(Col, L);
end
else
begin
if CurChar in QuoteChars then
if QuoteChar = #0 then
QuoteChar := CurChar
else if CurChar = QuoteChar then
QuoteChar := #0;
if QuoteChar = #0 then
begin
if CurChar = BreakStr[1] then
begin
ExistingBreak := StrLComp(Pointer(BreakStr),
Pointer(@Line[Pos]), BreakLen) = 0;
if ExistingBreak then
begin
Inc(Pos, BreakLen-1);
BreakPos := Pos;
end;
end;
if not ExistingBreak then
if CurChar in BreakChars then
BreakPos := Pos;
end;
end;
Inc(Pos);
Inc(Col);
if not (QuoteChar in QuoteChars) and (ExistingBreak or
((Col > MaxCol) and (BreakPos > LinePos))) then
begin
Col := 1;
Result := Result + Copy(Line, LinePos, BreakPos - LinePos + 1);
if not (CurChar in QuoteChars) then
begin
while Pos <= LineLen do
begin
if Line[Pos] in BreakChars then
begin
Inc(Pos);
ExistingBreak := False;
end
else
begin
ExistingBreak := StrLComp(Pointer(@Line[Pos]), sLineBreak,
Length(sLineBreak)) = 0;
if ExistingBreak then
Inc(Pos, Length(sLineBreak))
else
Break;
end;
end;
end;
if (Pos <= LineLen) and not ExistingBreak then
Result := Result + BreakStr;
Inc(BreakPos);
LinePos := BreakPos;
Pos := LinePos;
ExistingBreak := False;
end;
end;
Result := Result + Copy(Line, LinePos, MaxInt);
end;
function WrapText(const Line: string; MaxCol: Integer): string;
begin
Result := WrapText(Line, sLineBreak, [' ', '-', #9], MaxCol); { do
not localize }
end;Ant?nio
function CharLength(const S: string; Index: Integer): Integer;
begin
Result := 1;
assert((Index > 0) and (Index <= Length(S)));
if SysLocale.FarEast and (S[Index] in LeadBytes) then
Result := StrCharLength(PChar(S) + Index - 1);
end;Please do not post copyrighted code here.
Bart
Delphi / Kylix Cross-Platform Runtime Library } { System Unit } { } { Copyright (c) 1988-2002 Borland Software Corporation } { } { This file may be distributed and/or modified under the terms of the } { GNU General Public License version 2 as published by the Free Software } { Foundation and appearing at http://www.borland.com/kylix/gpl.html.
Ant?nio
2010/10/7 Bart :
Anyway, this function does not work.
Ant?nio
Delphi / Kylix Cross-Platform Runtime Library } { System Unit …
That may be so, but then we would have to put the Borland copyright notice in all source files that use this. This is not possible/allowed.
Michael.
You should not use this because it does not work.
Ant?nio
Delphi / Kylix Cross-Platform Runtime Library } { System Unit …
My bad. Please forgive.
Bart