Member Modifiers

Each member of a Class, Record or Interface can sport a range of modifiers that affect how the member works or is accessed.

Member Modifiers are provided after the ; that closes the member declaration. Multiple modifiers can be provided, each followed by/separated by a semicolon.

method Foo; virtual; private; empty; locked on fBar;
begin
  ...
end;

The order of modifiers has no relevance, but note that combinations of modifiers that would be contradictory or non-sensible (such as abstract;override; or async;iterator;") are not permitted.

If an implementation for a method is provided in-line as part of the Unified Class Syntax, modifiers must be listed before the begin or require keyword that starts the method body.

Virtuality Modifiers

The concepts of polymorphism and virtuality of members are shared between all type members, and across all Elements languages that support classes. Please read more about this in the Polymorphism topic.

Methods, Properties, Events and (in a limited fashion) Constructors can take part in polymorphism, so the following modifiers are allowed on these kinds of members.

  • virtual — marks a member as virtual, so that descendent classes can override it.
  • abstract — marks a member as abstract. Abstract members cannot have an implementation (or read/write or add/remove statements, for properties and events), and descendent non-abstract classes must to override the member.
  • override — marks a member as overriding a virtual or abstract event from the base class.
  • final — marks an overridden member as final, so that descendants cannot override it further.
  • reintroduce — indicates that the member replaces a member of the same name in the base class without overriding it or participating in polymorphism.
method OverrideMe; virtual;

Visibility Modifiers

Each member can be marked with an individual Visibility Level that overrides the level set by the visibility section it is defined in (if any).

Please refer to the Member Visibility Level topic for a detailed description of visibility levels.

method VerySecret; private;

Static Members

By default, members are considered to be defined on the instance of a type. That means that an instance is needed to access them, and any changes they make will affect that instance.

Methods, Properties, Events, Fields and Constructors can optionally be marked as static, which means they can be accessed without reference to an instance and (in the case of properties, events and fields) their state is shared globally, as a single copy for the entire type.

A member can be marked as static by applying the static modifier (or, for backward compatibility, by prefixing it with the class keyword):

method MyClassMethod: String; static;    // static method on the class itself
class method MyOtherClassMethod: String; // also a static method on the class itself

Other Modifiers

The following additional modifiers are supported for various member types. Note that (with the exception of async), all modifiers marked as available "for methods only" apply to all method-like members, including Constructors and Operators.

  • async — (Methods only) marks a method as running asynchronously from the caller. When called, an asynchronous method returns control to the caller immediately, while the actual processing happens in the background. Asynchronous methods cannot have var or out parameters, and if they return a value, that value will be returned to the caller in form of a Future. On .NET, asynchronous methods are also compatible with the await keyword. See also Async Expressions.
  • copy — (Properties only) marks the property with the "Copy" meta-flag, for Cocoa.
  • default — (Properties only) marks the property to be (a) default Indexer Property for the containing type.
  • deprecated — marks the member as "deprecated", and causes a warning to be emitted if it is accessed from code. An optional constant String message can be provided.
  • empty — (Methods only) marks the method as containing no code. A method marked as empty cannot have an implementation body. In contrast to abstract methods, empty methods can be called safely at runtime, they just perform no action.
  • external — (Methods and Fields only) marks a method as being a declaration for a method or function that is linked in from an external library. Usually used in combination with the [DllImport] aspect to define a method that calls, for example, a native .dll on .NET. No implementation body may be provided.
  • implements   ISomeInterface.SomeMember — indicates that the member implements the given member of an interface, even though it may not match that method in name. See Explicit Interface Implementations.
  • implements   ISomeInterface — (Properties and Fields only) indicates that the member points to a type that provides an implementation for the whole interface. See Explicit Interface Implementations.
  • inline — (Methods only) marks the method to be compiled as inline. This means that no actual distinct method will be emitted into the executable, instead the code of the method will be inserted inline wherever the method is called. This can provide small speed improvements when used on simple but often-called methods. Inlined methods cannot participate in Polymorphism or in dynamic method dispatching at runtime.
  • iterator — (Methods only) marks the method as an Iterator method that returns a dynamically generated sequence of items.
  • lazy — (Properties only) in combination with an initialization value for the property, this will make sure that the initial value is only calculated if and when when the property is first accessed (opposed to as part of the class's instantiation). Lazy properties can be readonly or read/write, but must have an initialization expression. When a lazy property is written to before it's first read, the initial value is not evaluated at all. The accessors for Lazy properties are thread safe.
  • locked — makes sure that all access to the method is thread safe and synchronized, so that only one single thread can execute the method at a time. See also Locking Statements.
  • locked on   Expression — optionally provides an expression that will be used to synchronize the access.
  • mapped to — (Mapped Types member only) marks the member to be mapped to a member in the original class.
  • notify — (Properties only) will cause the property to emit platform-specific Notifications when the property is changed. See also Property Notifications.
  • optional — (Interface members only) marks the member as optional, on the Cocoa platform.
  • partial — (Methods only) marks the method for special behavior inside a Partial Type as discussed in that topic. Often combined with empty.
  • readonly — (Properties and Fields only) marks the member as read-only, so that it can only be assigned from the constructors or via an initializer, and is immutable from that point on (both internally within the defining type and externally).
  • raises — adds a Java Throws Definition to declare that the member can raise exceptions. It can optionally be followed by a comma-separated list of Exception type names. (Available on the Java platform only.)
  • unsafe — marks a member as using "unsafe" code, such as direct pointer manipulation, on a managed platform. (Available on .NET only.)
  • where — provides Constraints on Generic Methods or Properties.
  • volatile — (Fields only) marks the field as volatile, meaning it is safe to be changed from multiple threads at once. A field marked as volatile won't be optimized by the compiler or runtime in optimizer phases that assume single-threaded access. Each access of the field will always read/write directly from/to memory, bypassing any caching. It also guarantees that only one CPU core at a time reads or writes this field at a given time.

Legacy Modifiers

The following additional modifiers are supported for various member types. Note that (with the exception of async), all modifiers marked as available "for methods only" apply to all method-like members, including Constructors and Operators.

See Also