On 2 Jun 2003 at 21:34, Frank Heckenbach wrote:
I recently came about the issue of overriding non-virtual methods by virtual ones. GPC currently allows this, but it may be slightly confusing. BP allows it as well, so we shouldn't forbid it. But should we warn? (Always or unless `--borland-pascal' was given?)
A warning except under '--borland-pascal' is fine. Another thing - an object with virtual methods but no constructor causes confusion under BP - e.g.,
type a = object procedure p; end;
b = object (a) procedure p; virtual; end;
procedure a.p; begin writeln ('a'); end;
procedure b.p; begin writeln ('b'); end;
var foo : a; bar : b;
begin foo.p; bar.p; end.
If this example is compiled with BP then, only 'a' gets printed (BP gives no warning, but silently compiles what it considers to be a faulty program).
Compiled with FPC, you get these warnings: a.pas(6,7) Warning: Virtual methods are used without a constructor in "b" a.pas(30,2) Warning: Variable "bar" does not seem to be initialized
When you run the program, 'a' gets printed, and then a GPF.
Compiled with Delphi, you get no warning, and both 'a' and 'b' get printed. Ditto with GPC, even with '--borland-pascal'.
Add a constructor and a constructor call before the call to 'b.p' and everything is alright under BP and FPC.
So, GPC's current treatment of objects with virtual methods but no constructor seems (at least with the trivial examples) to be consistent with Delphi, but not with BP when using '--borland-pascal'.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/