Virtual (keyword)

From RemObjects Software

Jump to: navigation, search

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



The "virtual" directive

Supply the virtual directive to allow descendant classes to override the class member.

Applies to

Non-virtual methods are static and their addresses are determined at compile time. Virtual method addresses, though, are calculated at runtime.


Abstract class members

By definition, an abstract member has to be virtual also (else there is no way to override it) and so Oxygene allows you to omit 'virtual' when 'abstract' is supplied.

To prevent a member from being overridden, see final and to stop any member see Sealed Classes.


Example of virtual and override

type
  Class1 = class
    procedure Show; virtual; empty;
  end;

  Class2 = class(Class1)
    procedure Show; override;
    procedure Test;
  end;

Note the use of empty here. An implicit empty implementation of Show is provided for Class1. Class2 does not need to provide an overridden Show method. If, however, Class1 was declared as follows, then Class2 would need to declare Show, otherwise it would be an abstract class too:

type
  Class1 = class
    procedure Show; abstract;
  end;


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