%Library.String

From CacheWiki
(Redirected from %String)
Jump to: navigation, search

Contents

TRUNCATE parameter

In earlier versions the default setting for the TRUNCATE parameter of a string is 1 (truncate at the maximum allowed length). This results in the default behaviour of an application being to truncate all string data at 50 characters.

Invariably this is not desirable behavior, so it is good practice to sub-class %Library.String with your own class and change the default value of TRUNCATE to 0.

MAXLEN parameter

The MAXLEN parameter has no effect on string properties unless the class they belong to has it's PROPERTYVALIDATION value set to 1 or, in the case of a Persistent class to 1 or 2.

The default value of the maximum length of a string property is 50 characters. It is unlikely that this is the correct or appropriate maximum length for any data in you application.

It is recommended that you sub-class %Library.String with your own class and change the default MAXLEN parameter to 1. This will force the correct length of each property to be set by the developer rather than leaving it to luck.

Sub-classed example

The following is an example of a class that can be used in place of %Library.String to implement improved and preferred behavior:

Class My.String Extends %String [ ClassType = datatype, ProcedureBlock ]
{

/// Do not silently truncate strings.  Overlength strings will 
/// now throw and error on being saved in a persistent class.
Parameter TRUNCATE As BOOLEAN = 0;

/// Force the maximum length to be set to an appropriate value.
Parameter MAXLEN As INTEGER = 1;

}

See Also

Long Strings

Personal tools