Delphi - Declaring Methods

Subroutines and Functions associated with classes are called Methods.


One of the reasons to use objects is polymorphism. This is indicated with the virtual and override directives. This is used by defining variables of the base class type and assigning them to objects of one of the derived types. This way you can treat many different types of objects in a similar manner, but the actual method is based on the specific type of object. (Examples explain this much better.) If the key word override is missing, then mehtod calls to the base class are not polymorphic and the base class method is called instead. In order to suppress compiler warnings, use the reintroduce directive if this is what you actually want.

virtual and dynamic perform the same function, but have different implementations.

abstract virtual methods define only the name, parameters, and return type of a method. One of the derived classes MUST define an implementation. You can not create objects until all the abstract methods of all the ancessor classes have implementations.


When 2 (or more) methods have the same name but different parameters, they are said to be Overloaded. The actual function called depends on the types of the parameters.

Default Parameters

Default parameters allow you to specify a method which can be called with a subset of the available parameters. For instance, There is no need to repeat the default values when the function details are specified.

In general, use overload for different types of parameters, default parameters for a different number of parameters.

(Search for default parameters in the Delphi 5 help.)

Named Parameters

Basically, Delphi 5 does not support Named Parameters.

I did find the following example, but that was all (see Named Parameters). Apparently, this syntax can only be used with Automation objects.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / Delphi / Methods.html