Lazarus

Programming => Packages and Libraries => RichMemo => Topic started by: Nicole on August 03, 2022, 09:48:00 am

Title: TEdit - copy to clipboard
Post by: Nicole on August 03, 2022, 09:48:00 am
edit1.CopyToClipboard

works and copies "edit1"

what I want is to copy is the text of the edit =
"edit1.Caption"

but
edit1.caption.CopyToClipboard
does not work.

What is the shortest way to copy the text of an edit to the Clipboard
Title: Re: TEdit - copy to clipboard
Post by: dseligo on August 03, 2022, 10:40:35 am
I use (I don't know what Edit1.Caption is):

Code: Pascal  [Select][+][-]
  1. Clipboard.AsText := Edit1.Text;
Title: Re: TEdit - copy to clipboard
Post by: Ally on August 03, 2022, 10:48:10 am
Or like this:
Code: Pascal  [Select][+][-]
  1.   Edit1.SelectAll;
  2.   Edit1.CopyToClipboard;
Title: Re: TEdit - copy to clipboard
Post by: rvk on August 03, 2022, 10:52:32 am
What is TEdit.Caption?
Why is there a Catpion for the TEdit and why are you using that.
For the content of a TEdit you should use TEdit.Text (not Caption).

TEdit doesn't have a caption (which I assume could be confused with a connected label).

TEdit.CopyToClipBoard is implemented like this:
Code: Pascal  [Select][+][-]
  1.   if (ACustomEdit.EchoMode = emNormal) and (ACustomEdit.SelLength > 0) then
  2.     Clipboard.AsText := ACustomEdit.SelText;

So it actually only copies selected text. I'm not sure why.
So either do Edit1.SelectAll directly in front of Edit1.CopyToClipBoard or folow the suggestion of dseligo.
(Ah, Ally beat me to it :) )
TinyPortal © 2005-2018