A property is an attribute of a LiveCode object. Each type of object has many built-in properties, which affect the object's appearance or behavior. You can also define custom properties for any object, and use them to store any kind of data.
Create a Stack
Create a new stack, name it 'Properties' and add a scrolling field and a button. Drag the field out to fill most of the area.
Open the Property Inspector of the Field
To open the property inspector of the field:
1. Select 'Edit' mode
2. Select the field
3. Click 'Inspector' in the Toolbar
You can also open the Property Inspector from the Object menu or by right clicking the object and selecting Object Inspector from the menu or by double clicking on the field.
The first pane that you see is the 'Basic Properties'. This is where you can change properties such as visibility, whether an object is disabled, border size etc. The properties that are available depend on the object type, this is a field so properties such as 'Don't wrap' can be set.
Try changing some properties, toggling visibility, switching off scrollbars etc.
Additional properties can be accessed by selecting different options in the tabs along the top. Notice that there is a >> showing that there are more panes than we can see (1).
You can set any property of an object using the Property Inspector: text size, font, background color, width, visibility, graphic effects.
Play around with some of the properties and see what you can do.
Object Specific Properties
Now select the button, if the Property Inspector is open it changes to display the properties of the button. If the Property Inspector is not on screen open it.
As mentioned in the previous step some properties are object specific. The 'Basic Properties' pane for the button has some properties that are the same as those of fields, visibility, opacity etc but also has properties that only apply to buttons, such as whether it is a default button.
The Property Inspector always display the properties for the selected object. If multiple objects of different types are selected only the common properties, such as width or height are shown.
Setting Properties in Script
All properties can also be set by script. For example:
set the visible of field 1 to true
is the equivalent of ticking the Visible option in the Property Inspector for the field.
You can find the name of a property by hovering over its description in the Property Inspector. If you prefer you can set the Property Inspector to display property names rather than descriptions. To do this open the Preferences and under General choose:
Property labels are: Name of LiveCode property.
Getting the Value of a Property
You can retrieve the value of a property using the get or put commands. You can put the value into a variable or use it directly.
Getting the value of a property:
get the visible of field 1
Putting the value of a property into a variable:
put the visible of field 1 into tVisible
Using the value of a property directly:
if the visible of field 1 then
Most properties are specific to the object they are part of, and affect only that object. However, some properties of an object, such as its color and text font, take on the settings of the object above it in the object hierarchy.
For example, if a field's foreground(text) color property is not specified the field takes on the foreground color of the card that owns it. If no foreground color is specified for the card either, the stack's foreground color is used, and so on.
This means you can set a foreground color for a stack, and every object in it automatically uses that color, without your having to set it for each object.
This process of first checking the object, then the object's owner, then the object that owns that object, and so on, is called inheritance of properties. Each object inherits the text color of the object above it in the hierarchy.
Similar inheritance rules apply to the backgroundColor, topColor, bottomColor, borderColor, shadowColor and focusColor properties, to their corresponding pattern properties, and to the textFont, textSize and textStyle properties
A custom property is a property that you create for an object, in addition to its built-in properties. You can define custom properties for any object, and use them to store any kind of data. You can create as many custom properties for an object as you want.
Use a custom property when you want to:
- associate data with a specific object
- save the data with the object in the stack file
- access the data quickly
Creating Custom Properties using the Property Inspector
You can create custom properties in the Property Inspector or in script.
To create a custom property in the Property Inspector select the object and open the Property Inspector. Select 'Custom Properties' from the drop down menu(1).
Then click the 'New Custom Property' button(2) to create a new custom property, name it and then set the value (3).
Creating Custom Properties in script
You can create a custom property in script by setting the new property to a value. If you set a custom property that doesn't exist, LiveCode automatically creates the custom property and sets it to the requested value.
This means that you can create a custom property in a handler or the message box, simply by using the set command.For example:
set the cMaximumLines of field 1 to 20
Getting and Setting the Value of a Custom Property
You get and set the value of a custom property in the same way as a built in property.
Setting the value of a custom property:
set the cMaximumLines of field 1 to 50
Retrieving the value of a custom property:
get the cMaximumLines of field 1