Page 1 of 1
One object to inherit all properties and styles of another
Posted: Mon Dec 13, 2021 6:44 pm
by kaveh1000
I have a set of 3 "master" objects:
button
field
group
I want to create new objects via script, then set the style and properties of each object to those the corresponding master object. This includes:
showborder
opaque
threeD
borderfill
outerglow
etc
I am doing this ok in the following way:
Code: Select all
set the dropshadow of group sCurrentName to the dropshadow of group template of stack "settings"
set the innershadow of group sCurrentName to the innershadow of group template of stack "settings"
etc
But there are so many. Is there a shortcut to set all properties without naming each one?
Regards
Kaveh
Re: One object to inherit all properties and styles of another
Posted: Mon Dec 13, 2021 7:14 pm
by FourthWorld
If the objects were all of the same type, you could "set the properties of ThisObject to the properties of ThatObject".
But since they are of different types there will be some properties of each not supported by the others.
If you do this often you may find it handy to write a command for that, which takes a list of desired properties as a param along with an object descriptor for the source object and another for the destination object. With that you can walk through the relevant properties in a loop.
Re: One object to inherit all properties and styles of another
Posted: Mon Dec 13, 2021 7:55 pm
by andresdt
Well I think you can use the
copy command or the
clone command.
Code: Select all
clone [the long id of the object you use as a template]
or
Code: Select all
copy [the long id of the object you use as a template] to copy this card
Re: One object to inherit all properties and styles of another
Posted: Mon Dec 13, 2021 9:49 pm
by dunbarx
Hi.
Know also that there are "templates" for each object. For example, the "templateField" is a virtual object in which one can set all its properties. So if you make a field just the way you want it, and
Code: Select all
set the properties of the templateField to the properties of fld "yourFavoriteField"
then every new field you create will inherit those properties. Note that the loc is such a property, and so the new field will appear at that loc each time you make a new one.
This can be a boon, and also a pain, since if you do not want the next field created to have those particular properties, you must remember to
which restores the defaults.
But you can manage this. For example, you might have a handful of fields with various properties. You can set the templateField to any one of them just before you actually create a new field, and that field will come out as you specified. You just have to juggle as you go...
Craig
Re: One object to inherit all properties and styles of another
Posted: Tue Dec 14, 2021 9:59 am
by kaveh1000
@Craig and @Richard. After decades I should really have guessed:
set the properties of ... to the properties of ...
LiveCode is more intuitive than we imagine! I have not been able to test because of another bug but sounds like I need one of these for each control type, i.e. button, field, group.
@andres I have a different control that I need to set properties for, so I cannot simply copy.
Thank you all.
Regards
Kaveh