On 25 Jul 2003 at 23:49, Frank Heckenbach wrote:
Peter N Lewis wrote:
In Mac Pascal, each method name must be unique within any object (including inherited objects, recursively). A super-object may override an existing method in an (recursively) inherited object (ie, define a method with an already existing name) , if the new definition exactly matches the old definitions prototype, and the keyword "override" is specified. Otherwise, yes it is an error.
So that's another incompatibility to BP. You may say that they don't really conflict since either way (with and without `override') would be an error in one of the dialects. But it would mean that if by default we allow the union of both dialects, `override' would mean almost nothing.
Override exists in Delphi as well. Contrary to the BP-style objects, you need to use "override" if you want to override a method. These excerpts are from the Delphi 7 help file:
"Overriding a method means extending or refining it, rather than replacing it. A descendant class can override any of its inherited virtual methods.
To override a method in a descendant class, add the directive override to the end of the method declaration.
Overriding a method causes a compilation error if The method does not exist in the ancestor class. The ancestor's method of that name is static. The declarations are not otherwise identical (number and type of arguments parameters differ)."
....
"If a method declaration specifies the same method identifier and parameter signature as an inherited method, but doesn't include override, the new declaration merely hides the inherited one without overriding it. Both methods exist in the descendant class, where the method name is statically bound. For example,
type T1 = class(TObject) procedure Act; virtual; end; T2 = class(T1) procedure Act; // Act is redeclared, but not overridden end; var SomeObject: T1; begin SomeObject := T2.Create; SomeObject.Act; // calls T1.Act end; " ..... "To make a method virtual or dynamic, include the virtual or dynamic directive in its declaration. Virtual and dynamic methods, unlike static methods, can be overridden in descendant classes. When an overridden method is called, the actual (runtime) type of the class or object used in the method call--not the declared type of the variable-- determines which implementation to activate.
To override a method, redeclare it with the override directive. An override declaration must match the ancestor declaration in the order and type of its parameters and in its result type (if any).
In the following example, the Draw method declared in TFigure is overridden in two descendant classes.
type TFigure = class procedure Draw; virtual; end; TRectangle = class(TFigure) procedure Draw; override; end; TEllipse = class(TFigure) procedure Draw; override; end;
Given these declarations, the following code illustrates the effect of calling a virtual method through a variable whose actual type varies at runtime.
var Figure: TFigure; begin Figure := TRectangle.Create; Figure.Draw; // calls TRectangle.Draw Figure.Destroy; Figure := TEllipse.Create; Figure.Draw; // calls TEllipse.Draw Figure.Destroy; end; "
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/