Until now, there was only one way to create a class property:
property <propertyName> : <type>
Starting with 4D 20 R5, we enhance the property declaration. As for variables, you can now declare and initialize your property on one line, as described below:
inferred type
property <propertyName> := <value>
Here, the type is omitted and will be determined by the compiler or interpreter based on the provided value. To prevent compilation errors, it is advisable to employ this approach exclusively with scalar types originating from values, commands, or methods.
Example:
//BLOB
property myBlob:=GetBlob()
//Boolean
property myBool:=True
//Null
property myNull:=Null
//Real
property myNum:=(569/2)
//Object
property myObj:={att1: 1}
//Text
property myText:="Hello"
//Collection
property myCol:=[1; 2; 3]
//Date
property myDate:=Current date
//Time
property myTime:=Current time
//Picture
property myPicture:=GetPicture()
// Properties must be declared before class constructor or functions.
Class constructor
Declared Type and initialization
property <propertyName> : <type> := <value>
As for the variable declaration, the property is created with the given type and then initialized with the value.
This declaration type must be used when you initialize a property with a type like a class attribute, an interprocess variable, or a global one. If you don’t specify the type in these cases, the interpreter and the compiler will evaluate the won’t be able to determine the type and will use a variant type instead. For example:
property myAttribute:=JSON Parse(GetJson()).myAttribute
// The interpreter and the compiler don't know the type of JSON Parse(GetJson()).myAttribute.
// The myAttribute property is declared as a variant