Code looks like this
var
t_style : TFontStyles;
t_str : WideString;
begin
RichEdit1.Lines.LoadFromFile('c:\hello.rtf');
t_str := RichEdit1.Lines.Text;
while n <= Length (t_str) do
begin
RichEdit1.SelStart := n;
RichEdit1.SelLength := 1;
t_style := RichEdit.SelAttributes.Style;
if t_style = [fsBold] then
bla bla
else
do something else;
n := n + 1;
end; //while
I'm obviously doing something wrong here, any clues much appreciated.
Graham
> if t_style = [fsBold] then
> bla bla
> else
> do something else;
That will only tell you if the style is bold and only bold. Since
style is a set you need to test the set for inclusion of a specific
element:
if fsBold in t_style then
--
-Mike (TeamB)
> t_str := RichEdit1.Lines.Text;
>
> while n <= Length (t_str) do
That is not a very efficient way to loop through the characters. Edit
controls always know how many characters they contain at all times, so you
should use the RichEdit's GetTextLen() method instead, ie:
var
t_style : TFontStyles;
n, len : Integer;
begin
RichEdit1.Lines.LoadFromFile('c:\hello.rtf');
len := RichEdit1.GetTextLen;
For n := 0 to len-1 do
begin
RichEdit1.SelStart := n;
RichEdit1.SelLength := 1;
t_style := RichEdit.SelAttributes.Style;
if fsBold in t_style then
// style includes bold
else
// style does not include bold
end;
end;
Gambit
If I need to get the character and the attribute, do I have to revert to my
scheme or is there a neater way to get at each character.
And finally, I understand that these RichEdit controls are wrappers around
the Windows control, so as Windows upgrades, and possibly changes its
RichEdit control, does the Delphi control also update? Or are the Delphi
RichEdit and the TntRichEdit based on a fixed version.
Just so you know what I am trying to achieve:
Basically I have my own editor which works in Unicode. It has a simple RTF
import mechanism which could be better. Using the RichEdit control seems a
good way to decode the RTF file into characters and attributes to import
into my editor.
Regards
Graham
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:42b70bb0$1...@newsgroups.borland.com...
> If I need to get the character and the attribute, do I have to revert
> to my scheme or is there a neater way to get at each character.
There is no way (that I know of, anyway) to get both the character and its
attributes in a single operation. You have to retreive them separately.
> And finally, I understand that these RichEdit controls are wrappers
> around the Windows control, so as Windows upgrades, and possibly
> changes its RichEdit control, does the Delphi control also update? Or
> are the Delphi RichEdit and the TntRichEdit based on a fixed version.
I cannot comment on TntRichEdit, but TRichEdit always uses v1.0 of the
RichEdit control (Microsoft is up to v4.1 now). To take advantage of newer
versions, you would have to write a custom descendant class, or use a
third-party one, that loads the desired version internally.
> Basically I have my own editor which works in Unicode. It has a simple
> RTF import mechanism which could be better. Using the RichEdit control
> seems a good way to decode the RTF file into characters and attributes to
> import into my editor.
I disagree. It sounds like you are trying to use one visual control to
parse content that is meant for another visual control. You would be better
off writing/finding an actual RTF parser instead. Then you can get the RTF
content directly into your editor without using another visual control to do
the work.
Gambit
>> If I need to get the character and the attribute, do I have to revert
>> to my scheme or is there a neater way to get at each character.
>
> There is no way (that I know of, anyway) to get both the character and its
> attributes in a single operation. You have to retreive them separately.
However you may want to look at ConsistentAttributes.
It may be more efficient to extend the SelLenght until ConsistentAttributes
changes and then deal with a whole block of characters known to have the
same atttibs.
(But there is no other way basically to get attribs, and its slow slow
slow!)
>> And finally, I understand that these RichEdit controls are wrappers
>> around the Windows control, so as Windows upgrades, and possibly
>> changes its RichEdit control, does the Delphi control also update? Or
>> are the Delphi RichEdit and the TntRichEdit based on a fixed version.
>
> I cannot comment on TntRichEdit,
I think its a wrapper for v3.
> but TRichEdit always uses v1.0 of the
.. That's not the whole story, as with the later implementations, as the v1
becomes a stub, which calls into the other DLL and gets it to create a v2
with restricted functionality..
> I disagree. It sounds like you are trying to use one visual control to
> parse content that is meant for another visual control. You would be better
> off writing/finding an actual RTF parser instead.
Writing one of those is no mean task!
> Writing one of those is no mean task!
Which is why I also mentioned *finding* a third-party pre-written parser.
Gambit
I realize that would need a RichEdit control that supports V4 to solve this
anyway.
Thanks for all your thoughts though.
Regards
Graham
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:42b9d3da$1...@newsgroups.borland.com...