Default (Compiler Magic Function)

From RemObjects Software

Jump to: navigation, search

This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.



default returns the default value of the specified type.
For Classes, this will be nil, for Records, this will be either 0 or for composit Records, this is an instance with all fields set to default.
You should be careful when assuming default values for Enums. When no 0 value has been defined, the underlying default value is still 0, but accessing it can result in an exception...

type
  MyRecordType = record
  public
    MyField : Integer
  end;
  MyEnumType1 = enum(One, Two, Three);
  MyEnumType2 = enum(None= 0, One, Two, Three);
...
var myInt    := default(Integer); // 0
var myString := default(String) // nil
var myRecord := default(MyRecordType); // myRecord.MyField is 0
var myEnum1  := default(MyEnumType1); // invalid value, it is 0 which is not defined
var myEnum2  := default(MyEnumType2); // None

method SomeClass.MyMethod<T>;
begin
  var myGeneric := default(T); // this is either nil, 0,
                               // or an empty record instance, depending on T


See Also


Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0 Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)

GlossaryKeywordsLanguage FeaturesPlatform FeaturesSamplesArticlesHow ToIssues

Personal tools