如何找出 tmemo 组件中的字符数?

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

我想做的是制作一个按钮,获取备忘录中的字符数量并将其输出到标签中

如果这看起来像是一个愚蠢的问题,我深表歉意,但我仍在学习 Delphi。

有几种方法可以获取 TMemo 中文本的长度。 最快的是询问 Windows 到 return 的长度(实现 TMemo 的是 Windows):

MemoLen := GetWindowTextLength(Memo1.Handle);

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

另一种方法是检索备忘录的文本并查询其长度:

MemoLen := Length(Memo1.Text);

最简单的方法是调用Memo的GetTextLen()方法:

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;