Quick start manual

7-8
Delphi Language Guide
Methods
Although MyObject holds an instance of TDescendant, it is declared as TAncestor. The
compiler therefore interprets MyObject.Value as referring to the (integer) field
declared in TAncestor. Both fields, however, exist in the TDescendant object; the
inherited Value is hidden by the new one, and can be accessed through a typecast.
Methods
A method is a procedure or function associated with a class. A call to a method
specifies the object (or, if it is a class method, the class) that the method should
operate on. For example,
SomeObject.Free
calls the Free method in SomeObject.
Method declarations and implementations
Within a class declaration, methods appear as procedure and function headings,
which work like forward declarations. Somewhere after the class declaration, but
within the same module, each method must be implemented by a defining
declaration. For example, suppose the declaration of TMyClass includes a method
called DoSomething:
type
TMyClass = class(TObject)
ƒ
procedure DoSomething;
ƒ
end;
A defining declaration for DoSomething must occur later in the module:
procedure TMyClass.DoSomething;
begin
ƒ
end;
While a class can be declared in either the interface or the implementation section of a
unit, defining declarations for a class’s methods must be in the implementation
section.
In the heading of a defining declaration, the method name is always qualified with
the name of the class to which it belongs. The heading can repeat the parameter list
from the class declaration; if it does, the order, type and names of the parameters
must match exactly, and if the method is a function, the return value must match as
well.