There is something funny going on with TRichEdit (D7).
When I use SelAttributes on a selected text portion with RichEdit.WordWrap
set to false,
all the positionng is correctly done. But when I do the same thing with
RichEdit.WordWrap
set to true, positioning is offset by CRLF functions in SOME RichEdits, but
not in others!
So if I turn RichEdit.WordWrap to False, then do the text selection and
SelAttributes,
then set RichEdit.WordWrap to True (for visual readability purposes), the
text in SOME
RichEdits goes into the formatted rich text description instead of the
original text.
In all RichEdits, I have PlainText set to False. I'm using four RichEdits,
and they all have
the exact same property values, as verified in the object inspector.
Here's the latest code:
var OldStyle : TFontStyles;
OldColor : TColor;
procedure TfmGetAllHRSectionsOfAPatentString.HighlightWord( RichEdit :
TRichEdit;
TotalLen :
Integer;
LineCount :
Integer;
I, Len :
Integer );
begin
RichEdit.SelStart := I-1;
RichEdit.SelLength := Len;
RichEdit.SelAttributes.Color := clRed;
RichEdit.SelAttributes.Style := [fsBold];
RichEdit.SelLength := 0;
RichEdit.SelStart := TotalLen;
RichEdit.SelAttributes.Style := OldStyle;
RichEdit.SelAttributes.Color := OldColor;
end;
procedure TfmGetAllHRSectionsOfAPatentString.HighlightKeyWords( RichEdit :
TRichEdit );
var TotalCharCount : Integer;
LastChar : Char;
NextChar : Char;
I,L : Integer;
AWord : string;
EndOfWord : Boolean;
TheText : string;
LineCount : Integer;
begin
{Highlight keywords and their synonyms}
OldStyle := RichEdit.SelAttributes.Style;
OldColor := RichEdit.SelAttributes.Color;
TheText := RichEdit.Lines.Text;
TotalCharCount := Length(TheText);
NextChar := ' ';
I := 1;
LineCount := 0;
RichEdit.Lines.BeginUpdate;
while (I<(TotalCharCount-1)) do
begin
LastChar := NextChar;
NextChar := TheText[I];
if NextChar=#$D
then LineCount := LineCount+1
else if IsSeparator(LastChar)
then if IsAlpha(NextChar)
then begin
L := 1;
EndOfWord := False;
while ( ((I+L)<=TotalCharCount)
and(not EndOfWord)) do
begin
if IsSeparator(TheText[I+L])
then begin
AWord := Copy(TheText,I,L);
if
(KeysPlusSynonyms.IsBoundString(AWord)>-1)
then HighlightWord( RichEdit,
TotalCharCount,
LineCount,
I,
L);
EndOfWord := True;
end;
L := L+1;
end;
NextChar := TheText[I+L-1];
I := I+L-1;
end;
I := I+1;
end;
RichEdit.Lines.EndUpdate;
RichEdit.Invalidate;
Application.ProcessMessages;
end;
And in the main routine, three RichEdits are called:
...
HighLightKeywords(reDescription);
HighLightKeywords(reClaims);
HighLightKeywords(reAbstract);
...
Here is the text copied from a RichEdit with WordWrap set to True:
BACKGROUND OF INVENTION
This invention relates generally to computer systems and more specifically
to the memory portions of such systems. The subject matter of this invention
is related to the subject matter of the prior inventions entitled
GARBAGE-COLLECTING MEMORY MODULE, Ser. No. 07/994,517, filed Dec. 21, 1992
(now U.S. Pat. No. 5,560,003, issued Sep. 24, 1996) and OBJECT SPACE MANAGER
CIRCUIT, Ser. No. 08/176,940, filed Jan. 4, 1994, (pending).
As you can see, the red bold font only works properly for the first four
keywords, which happen to be on the first
line of text. After that, the red bold font is spaced away by a multiple of
the number of lines.
If I then turn WordWrap off and back on, the formatting text appears:
--------------------------------------------------------------------------
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil MS Sans Serif;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs16 BACKGROUND OF INVENTION
\par
\par \cf1\b This\cf0\b0 invention relates generally to computer systems
\cf1\b and\cf0\b0 more specifically to \cf1\b the\cf0\b0 memory portions of
such systems. \cf1\b The\cf0\b0 subject matter of th\cf1\b is i\cf0\b0
nvention is\cf1\b r\cf0\b0 elated to th\cf1\b e s\cf0\b0 ubject matter of
th\cf1\b e p\cf0\b0 rior inventions entitled GARBAGE-COLLECTING MEMORY
MODULE, Ser. No. 07/994,517, filed Dec. 21, 1992 (now U.S. Pat. No.
5,560,003, issued Sep. 24, 1996) and \cf1\b OBJ\cf0\b0 ECT SPACE MANAGER
CIRCUIT, Ser. No. 08/176,940, filed Jan. 4, 1994, (pending).
\par
-------------------------------------------------
Trying to do it programmatically by first setting WordWrap := False, then
marking
the SelAttributes, then setting WordWrap := True doesn't work, as it
generates the
formatting text instead of the readable text.
Does anyone know why this is happening, and what I can do
about it?
Thanks,
Rich
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi