Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Mar : Richedit, character position

www.cryer.info
Managed Newsgroup Archive

Richedit, character position

Subject:Richedit, character position
Posted by:"EricConway" (..@)
Date:Wed, 9 Mar 2005 15:09:55

Hello group

I've spent ages going through Google Groups threads, but I'm probably using the wrong search terms because I haven't been able to
find an answer to my question yet.
I'm trying to determine the index of the caret in a TRichEdit control - I PostMessage VK_END to the RichEdit immediately beforehand,
and I want to know what position it stops at (position from the beginning of the Text in the RichEdit - NOT the current line).

My current kludge is:

var
  i, j: Integer;
...
j := ARichEdit.Perform(EM_LINEFROMCHAR, -1, 0); // get current line
// get all characters up to caret position
for i := 0 to j do
  TempString := TempString + ARichEdit.Lines.Strings[i];
// determine caret position by counting all characters from start of Text
CaretPosition := Length(TempString) + j;

But that seems terribly inefficient - is there a better way?

Many thanks in advance

Replies:

www.cryer.info
Managed Newsgroup Archive