How to create a new label field programmatically?

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
cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

How to create a new label field programmatically?

Post by cbarbal » Tue Dec 18, 2018 3:33 pm

Hi all,

I found a response from dunbarx on a mailing list, but it gives me an error:

Code: Select all

Set up the templateField as a label field
Error description: set: no property specified
I have also looked at the Scripting Conference "Controls" of Klaus Major and I do not have it completely clear if it is necessary to do it property by property. I would like something easier and Klaus knows it but does not explain it :D
e.g. when you select the "Label" field tool, the following properties are already set for a "normal" field:

visible = true
locktext = true
##(field content cannot be edited)
hscrollbar = false
vscrollbar = false
showborder = false
etc...
Thanks in advance,

Carles

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Tue Dec 18, 2018 3:50 pm

Hi.

Read up on the "templateField" in the dictionary.

Make a field of some kind, perhaps a label field taken right from the tools palette. Set its name to "masterField" and put something you like to see into its contents. Now in a button somewhere:

Code: Select all

on mouseUp
 set the properties of the templateField to the properties of fld "masterField"
 create field "xx"
put "newestField" into fld "xx"
end mouseUp
Click on the button. You will find your new field to be a label field with all the properties of the original, with its own name ("xx") and with the contents "newestField".

Craig
Last edited by dunbarx on Thu Dec 20, 2018 2:51 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How to create a new label field programmatically?

Post by richmond62 » Thu Dec 20, 2018 12:26 pm

As a label field is just a field with some distinct properties one way to do this
is like this:

Code: Select all

create field "label"
> which creates a 'normal' field <

and then set the properties of the field to those of a label.

Here's something boring and predictable:

Code: Select all

on mouseUp
   put the properties of fld "zz" into zzArray
   create fld "xyz"
   set the properties of fld "xyz" to zzArray
end mouseUp
This will do EXACTLY the same thing as duplicating the label field "zz",
except that it will be directly on top of the original label field with the same name.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”