Problem copyng to the clipboard

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Problem copyng to the clipboard

Post by phaworth » Fri Jan 22, 2010 2:52 am

I'm trying to copy the label of an option menu button to the clipboard with this code:

Code: Select all

copy the label of button "xyz"
That results in the runtime error "chunk error in object expression" followed by the text of the button's label.

Is there a way to copy the label of a button onto the clipboard?

Thanks,

Pete

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Problem copyng to the clipboard

Post by sturgis » Fri Jan 22, 2010 3:32 am

look at the clipboard() function in your dictionary. IT can be used to determine if there is anything in the clipboard, and what type of data it is.

To put something into the clipboard, or get it from the clipboard look at clipboardData

The following puts the data into the clipboard.
set the clipboardData["text"] to the label of button "xyz"

At this point, you can look to see what type of data is in there.

put the clipboard
will return "text" and put it in the message box.

To get stuff back out of the clipboard is pretty straightforward too.
put the clipboardData["text"] into field "abc"

Quite a bit more good information in the dictionary, but this should get you started.


Edit: While it seems it should work as in your example, apparently copy can't figure out what to do with a property return. put char 1 to -1 of the label of button "xyz" works, but when you tack the copy on to the front it doesn't. /shrug. Either way, it still seems easier to me to use clipboardData directly to set and get values. Much more flexible unless you want to copy objects.

If anyone can point out a proper syntax/method to use copy to put label names and the like into a clipboard, i'd be curious to know how. Thx
Last edited by sturgis on Fri Jan 22, 2010 3:42 pm, edited 1 time in total.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Problem copyng to the clipboard

Post by phaworth » Fri Jan 22, 2010 6:18 am

Thanks, that works perfectly for what I want to do.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Problem copyng to the clipboard

Post by BvG » Fri Jan 22, 2010 5:55 pm

you can't copy the label of anything. the syntax in the dict is correct and says:
copy [object [to {card | group | stack} ]] | [chunk of field]

so it's either:
copy <any object> to <either card or group or stack
or
copy <chunk description> of <any field>

examples:
copy line 1 of field 2
copy button "it works" to this card


non working examples:
copy char 12 to 18 of the imagedate of graphic "nope"
copy the hilite of button "can't work" to group "too bad"
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Problem copyng to the clipboard

Post by phaworth » Fri Jan 22, 2010 6:23 pm

The clipboardData suggestion works fine for what I want to do. Still feel like copy ought to work - as pointed out a couple of posts ago isn't "char 1 to -1 of the label of button "xyz" a chunk? Yet copy won't work with it. No big deal though, all is working fine now.
Pete

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Problem copyng to the clipboard

Post by BvG » Sat Jan 23, 2010 2:08 am

yes, part one of the source is a chunk. however, part 2 of the chunk is _not_ a field. therefore it doesn't work.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply