January 15th, 2013, 06:16 AM
Basic text editor functionality
Hello everybody. I desperately need some help. I'm building a simple text editor. I can't figure out how to count the characters, rows and characters in selected text in richedit field and show the info in new form. Can you help me? I'm using Delphi 2007. Thank you.
January 15th, 2013, 06:57 AM
To get count of characters, use window message WM_GETTEXTLENGTH. Something like this:
Note that for this to work, the richedit must already has valid window handle.
function GetCountOfChars(ARichEdit: TRichEdit): Cardinal;
Result := SendMessage(ARichEdit.Handle, 0, 0);
To get count of rows, use the richedit's Lines property. It got a Count property which explains how many lines the richedit has.
To get count of selected characters, use the richedit's SelLength property.
January 15th, 2013, 07:55 AM
I'm not very good, can you show my an example. I know I have to use a variable to store the counting but I don't know how to do that. I suppose I need a loop. And in the other form Label#:= (my variable).
P.S. I did it! Here is the code:
procedure TForm1.Statistics1Click(Sender: TObject);