Recent

Author Topic: TEdit - copy to clipboard  (Read 308 times)

Nicole

  • Sr. Member
  • ****
  • Posts: 498
TEdit - copy to clipboard
« 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

dseligo

  • Hero Member
  • *****
  • Posts: 813
Re: TEdit - copy to clipboard
« Reply #1 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;

Ally

  • New Member
  • *
  • Posts: 44
Re: TEdit - copy to clipboard
« Reply #2 on: August 03, 2022, 10:48:10 am »
Or like this:
Code: Pascal  [Select][+][-]
  1.   Edit1.SelectAll;
  2.   Edit1.CopyToClipboard;

rvk

  • Hero Member
  • *****
  • Posts: 5017
Re: TEdit - copy to clipboard
« Reply #3 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