Skip to main content
Version: 20 R7 BETA

ST SET ATTRIBUTES

ST SET ATTRIBUTES ( {* ;} object ; startSel ; endSel ; attribName ; attribValue {; attribName2 ; attribValue2 ; ... ; attribNameN ; attribValueN} )

ParameterTypeDescription
*OperatorIf specified, object is an object name (string)
If omitted, object is a variable or a field
objectanyObject name (if * is specified) or
Text field or variable (if * is omitted)
startSelIntegerStart of new text selection
endSelIntegerEnd of new text selection
attribNameTextAttribute to set
attribValueText, IntegerNew value of attribute

This command is not thread-safe, it cannot be used in preemptive code.

Description

The ST SET ATTRIBUTES command can be used to modify one or more style attributes in the form object(s) designated by object.

If you pass the optional * parameter, this indicates that the object parameter is an object name (string). During execution, when the object has the focus, the command only applies to the object being edited and not to its data source (field or variable). The changes are only transferred to the source (and to any other objects using this same source) when the object being edited is validated either by losing the focus or with the Enter key. When the object does not have the focus, the command applies directly to the data source and the changes are immediately transferred to any other objects using the same source.
If you omit the * parameter, this indicates that the object parameter is a field or variable and you pass a field or variable reference instead of a string. The command applies directly to the field or variable and changes are immediately transferred to all the objects using this source, including the object with the focus.

Note: You can only use style attributes with Text type fields. Since Alpha type fields have a preset length, adding style tags would lead to a loss of data.

The definition of an attribute is carried out via the insertion or modification of HTML style tags within the text (for more information about this point, refer to the Design Reference manual). Note that ST SET ATTRIBUTES inserts style tags in all cases, even if the object designates text objects of the form that do not have the Multistyle property.

The startSel and endSel parameters can be used to designate the selection of text to which to apply the style modification(s) within the object. In startSel, you pass the position of the first character to be modified and in endSel, you pass the position of the last character to be modified plus one (the last character passed is not included in the modification). You can pass 0 in endSel to designate automatically the last character of the text (pass 1 in startSel to designate the first character of the text).
If the value of endSel is greater than the number of characters in the object, all the characters between startSel and the end of the text are modified. If startSel is greater than endSel (except when endSel value is 0, see above), the command does nothing and the OK variable is set to 0.
The startSel and endSel values do not take any style tags already present in the area into account. They are evaluated on the basis of raw text (text where style tags have been filtered).

4D provides predefined constants so that you can designate the selection limits automatically in the startSel and endSel parameters. These constants are found in the "Multistyle Text" theme:

ConstantTypeValueComment
ST End highlightLongint-1001Designates last character of current text selection in object (*)
ST End textLongint0Designates last character of text contained in object
ST Start highlightLongint-1000Designates first character of current text selection in object (*)
ST Start textLongint1Designates first character of text contained in object

(*) You must pass an object name in object to be able to use this constant. If you pass a reference to a field or variable, the command is applied to all the text of the object.

In attribName and attribValue, pass the name and the value, respectively, of the attribute to be modified. You can pass as many attribute/value pairs as you want. To specify the attribName parameter, use the predefined constants placed in the Multistyle Text Attributes theme. The value passed in the attribValue parameter depends on the attribName parameter:

ConstantTypeValueComment
Attribute background colorLongint8attribValue=Hexadecimal values or HTML color names (Windows only)
Attribute bold styleLongint1attribValue=0: remove bold attribute from selection
attribValue=1: apply bold attribute to selection
Attribute font nameLongint5attribValue=Font family name (string)
Attribute italic styleLongint2attribValue=0: remove italic attribute from selection
attribValue=1: apply italic attribute to selection
Attribute strikethrough styleLongint3attribValue=0: remove strikethrough attribute from selection
attribValue=1: apply strikethrough attribute to selection
Attribute text colorLongint7attribValue=Hexadecimal values or HTML color names
Attribute text sizeLongint6attribValue=Number of points (number)
Attribute underline styleLongint4attribValue=0: remove underline attribute from selection
attribValue=1: apply underline attribute to selection

Colors
If you pass the Attribute text color or Attribute background color constants in attribName, you must pass a string containing either an HTML color name or a hexadecimal color value in attribValue:

HTML color nameHexa value
Aqua#00FFFF
Black#000000
Blue#0000FF
Fuchsia#FF00FF
Gray#808080
Green#008000
Lime#00FF00
Maroon#800000
Navy#000080
Olive#808000
Purple#800080
Red#FF0000
Silver#C0C0C0
Teal#008080
White#FFFFFF
Yellow#FFFF00

Example

In this example, we modify the size and color of the text as well as the bold and underline attributes of the characters 2 to 4 of the field:

 ST SET ATTRIBUTES([MyTable]MyField;2;5;Attribute font name;"Arial";Attribute text size;10;Attribute underline style;1;Attribute bold style;1;Attribute text color;"Blue")

System variables and sets

After this command is executed, the OK variable is set to 1 if no error occurred; otherwise, it is set to 0. This is the case more particularly when style tags are not evaluated properly (incorrect or missing tags).

In the case of an error, the variable is not changed. When an error occurs on a variable when text is being evaluated, 4D transforms the text into plain text; as a result, the <, > and & characters are converted into HTML entities.

See also

FONT LIST
ST GET ATTRIBUTES