Page 1 of 1

How to create a new label field programmatically?

Posted: Tue Dec 18, 2018 3:33 pm
by cbarbal
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

Re: How to create a new label field programmatically?

Posted: Tue Dec 18, 2018 3:50 pm
by dunbarx
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

Re: How to create a new label field programmatically?

Posted: Thu Dec 20, 2018 12:26 pm
by richmond62
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.