Page 1 of 1
Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 01, 2014 9:20 am
by atout66
Hi to all,
Sorry to ask such an obvious question in appearance, but my script below does not work despite the consultation of the dictionary and the application of different examples.
I would like to understand why ?
Code: Select all
if the hilitedLine of field "myFld" is NOT empty then -- <"myFld"> is a list field
put the selectedText of fld "myFld" into laSelection -- OK, <laSelection> is not empty
copy char 1 to -1 of laSelection -- issue here !?! the dictionary adds <of me> but here it doen't apply
else --
I must add that
does not work either.
Kind regards, Jean-Paul.
Re: Copying a line of text into the clipboard
Posted: Thu May 01, 2014 9:55 am
by jmburnod
Bonjour Jean-Paul,
I think you need somethink like this
For a fld
Code: Select all
set the clipboarddata[text] to the selectedtext
For a listField
Code: Select all
get line (the hilitedlines of fld 1) of fld 1
set the clipboarddata[text] to it
Kind regards
Jean-Marc
Re: Copying a line of text into the clipboard
Posted: Thu May 01, 2014 10:35 am
by atout66
Merci Jean-Marc, tu as trouvé la solution
I'm going to avoid of thinking why my code didn't work, it's not the right day for that
Kind regards, Jean-Paul.
Re: Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 01, 2014 11:14 am
by Klaus
Lazy moi:
...
set the clipboarddata[text] to the selectedtext of fld 1
...
And this avoids using IT unneccessarily

Re: Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 01, 2014 11:45 am
by atout66
You're right Klaus, IT is allowed to do the less possible

Re: Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 01, 2014 1:59 pm
by Klaus
atout66 wrote:IT is allowed to do the less possible

Exactement!

Re: Copying a line of text into the clipboard
Posted: Thu May 01, 2014 4:03 pm
by magice
atout66 wrote:
I'm going to avoid of thinking why my code didn't work, it's not the right day for that
I prefer using Klaus' method, but if you want to know how to do it using "copy", you can try this.
Code: Select all
select the text of fld "myFieldName"
copy
I know it feels wrong throwing out a command without any parameters, but it works.
Re: Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 08, 2014 6:46 pm
by FourthWorld
Using the copy command without parameters may seem strange if you're used to more complex languages, or necessary if you're implementing an unusual interface.
The clipboard belongs to the user, and an application should preserve anything the user has explicitly placed in it. Using it for any other purpose risks overwriting data the user had copied that may be important to them, perhaps even for use in other applications unrelated to yours.
In most applications, copy works on an active text selection within an editable field. In that most common scenario, LiveCode makes it as simple as can be to do what you want while leaving the user in control:
...is all you need, provided the user has selected a range of text to copy.
It's very rare that copy is allowed for uneditable text in a list field. Offhand, I can't think of any examples where I've seen that. It may indeed be a very useful thing to provide in your specific application, but in such an unusual circumstance we can expect to need unusual syntax to support it.
Thankfully, as the others here have shown, LiveCode is flexible enough that it requires at most just a few extra tokens or a second line of code to do even uncommon things like this.
Re: Copying a line of text into the clipboard [SOLVED]
Posted: Thu May 08, 2014 8:45 pm
by atout66
Great lesson Richard, thanks

Re: Copying a line of text into the clipboard [SOLVED]
Posted: Mon Dec 20, 2021 1:31 am
by gilgml
@magice & @fourthworld : Neat and Slick
