How do I find out the number of characters in a tmemo component?

722 Views Asked by At

What I am trying to do is make a button that takes the amount of chars in a memo and output it in a label

I apologise if this seems like a silly question but I am still learning about Delphi.

2

There are 2 best solutions below

0
On BEST ANSWER

The easiest way is to call the Memo's GetTextLen() method:

Returns the length of the control's text.

procedure TForm1.Button1Click(Sender: TObject);
var
  Len: Integer;
begin
  Len := Memo1.GetTextLen;
  Label1.Caption := IntToStr(Len);
end;
1
On

There are several ways to get the length of text in a TMemo. The fastest is to ask Windows to return the length (It is Windows which implement a TMemo):

MemoLen := GetWindowTextLength(Memo1.Handle);

or

MemoLen := SendMessage(Memo1.Handle, WM_GETTEXTLENGTH, 0, 0);

Another way is to retrieve the text of the memo and query his length:

MemoLen := Length(Memo1.Text);