One object to inherit all properties and styles of another

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

One object to inherit all properties and styles of another

Post by kaveh1000 » Mon Dec 13, 2021 6:44 pm

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
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: One object to inherit all properties and styles of another

Post by FourthWorld » Mon Dec 13, 2021 7:14 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

andresdt
Posts: 156
Joined: Fri Aug 16, 2019 7:51 pm
Contact:

Re: One object to inherit all properties and styles of another

Post by andresdt » Mon Dec 13, 2021 7:55 pm

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 
Be kind, we all have our own wars.
https://torocruzand.com/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: One object to inherit all properties and styles of another

Post by dunbarx » Mon Dec 13, 2021 9:49 pm

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

Code: Select all

reset the templateField
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

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 539
Joined: Sun Dec 18, 2011 7:23 pm
Contact:

Re: One object to inherit all properties and styles of another

Post by kaveh1000 » Tue Dec 14, 2021 9:59 am

@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
Kaveh

Post Reply