How can I make a TWPRichText object justify the text (line up the right edges of each line of text)? I would have guessed WordWrap would do this, but that just makes the lines stretch from one side of the component to the other. Thanks.
justifying text
-
-
- Offizieller Beitrag
You need to assignj paralBlock to eaxch paragraph of the text, for example using 'CurraTAttr.Alignment)
Wordwrap works like TMemo.Wordwrap - it fits the text into the editor box.
Julian Ziersch
-
Thanks for the pointer!
procedure TFormMain.JustifyText();
var
ii, iPar: Integer;
begin{remove double spaces from earlier code}
with WPRichText1.Finder do begin
ToStart;
ReplaceAll(' ', ' ');
end;
{iterate through paragraphs}
iPar := WPRichText1.CountParagraphs;
for ii := 1 to iPar do begin
WPRichText1.CPParNr := ii;
WPRichText1.CurrAttr.Alignment := paralBlock;
end;WPRichText1.Update;
end; -
- Offizieller Beitrag
{iterate through paragraphs}
iPar := WPRichText1.CountParagraphs;
for ii := 1 to iPar do begin
WPRichText1.CPParNr := ii;
WPRichText1.CurrAttr.Alignment := paralBlock;
end;should be better written as
works 10 times faster :-)[/code]
-
I get an EAccessViolation message when I use that code. Is there some initialization of par that must be used?
-
Try
var par : PTParagraph;
par:=wpRichText1.firstPar;
while par<>nil do
begin
par.Align := paralBlock;
par := par^.next;
end;[/code] -
Looks like that should work. The error always occurred with the first iteration of the loop. I was wondering if the violation occurred because the variable hadn't been initialized, but I hadn't had time to work on it yet (I hate it when work gets in the way of the fun stuff ;) ). Thanks for the tip.
-
- Offizieller Beitrag
Well - sorry - forgot the line with 'FirstPar'.
Julian