4D v13.4

OBJECT SET STYLED TEXT

Home

 
4D v13.4
OBJECT SET STYLED TEXT

OBJECT SET STYLED TEXT 


 

OBJECT SET STYLED TEXT ( {* ;} object ; newText {; startSel {; endSel}} ) 
Parameter Type   Description
Operator in If specified, object is an object name (string) If omitted, object is a variable or a field
object  Form object in Object name (if * is specified) or Text field or variable (if * is omitted)
newText  Text in Text to insert
startSel  Longint in Start of selection
endSel  Longint in End of selection

The OBJECT SET STYLED TEXT command inserts the text passed in the newText parameter into the styled text field or variable designated by the object parameter. This command only applies to the plain text of the object parameter, without modifying any style tags that it contains. It can be used to modify, by programming, styled text displayed on screen.

 

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.

 

In newText, pass the text to be inserted. The OBJECT SET STYLED TEXT command is intended for working with rich text (multistyle) containing <span> type tags. In all other cases (more particularly, when working with plain text that contains the <, > or & characters), you must use the OBJECT SET PLAIN TEXT command. If you pass plain text containing the <, > or & characters to the OBJECT SET STYLED TEXT command, it does nothing. This is necessary behavior because if you insert a string such as "a>b" directly into rich text, it will distort the internal analysis of the <span> tags. In this case, "<" characters must be encoded beforehand as "&lt;", which can be done using the OBJECT SET PLAIN TEXT command (see also the example of this command).

The optional startSel and endSel parameters let you designate a selection of text in object. The startSel and endSel values give a selection of plain text, without taking any style tags found in the text into account. The action of the command varies according to the optional startSel and endSel parameters:

  • If you omit startSel and endSel, OBJECT SET STYLED TEXT replaces all the text of the object by newText,
  • If you only pass startSel or if the values of startSel and endSel are equal, OBJECT SET STYLED TEXT inserts the newText text into object beginning at startSel,
  • If you pass both startSel and endSel, OBJECT SET STYLED TEXT replaces the plain text set by these limits with the newText text.
  • 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 startSel is greater than endSel (except if endSel value is 0, see above), the text is not modified and the OK variable is set to 0.

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.

You want to replace the styled text selected by the user with the contents of a variable.

Here is the selected text:

The following contents are stored in the field:

After executing this code:

 vtempo:="Demonstration"
 GET HIGHLIGHT([Products]Notes;vStart;vEnd)
 OBJECT SET STYLED TEXT([Products]Notes;vtemp;vStart;vEnd)

The field and its contents are as follows:

Refer to the example of the OBJECT SET PLAIN TEXT command.

 
PROPERTIES 

Product: 4D
Theme: Object Properties
Number: 1115

The OK variable is changed by the command

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: 4D v12
Modified: 4D v12.1

 
SEE ALSO 

OBJECT Get plain text
OBJECT Get styled text
OBJECT SET PLAIN TEXT