On 22 Oct 2005 at 20:06, Waldek Hebisch wrote:
Prof. Abimbola A. Olowofoyeku (The African Chief) wrote:
On 22 Oct 2005 at 0:02, Waldek Hebisch wrote:
There is also question if constructors are mandatory for objects with virtual methods.
IMHO they should be - or at least a warning should be generated, except in Mac mode.
Constructors for Delphi and OOE classes will be inherited from base object, so there is no need to check for them. Other classes may work fine without constructors. So the check is debatable.
Consider this:
program afoo;
type foo = object procedure one; virtual; procedure two; virtual; end;
bar = object (foo) procedure two; virtual; procedure three; end;
procedure foo.one; begin writeln ('foo.one'); end;
procedure foo.two; begin writeln ('foo.two'); end;
procedure bar.two; begin writeln ('bar.two'); end;
procedure bar.three; begin writeln ('bar.three'); end;
var a1 : foo; b1 : bar; begin a1.one; a1.two; b1.one; b1.two; b1.three; end.
Compile and run this with BP, and you get garbage. With FPC, you get a warning at compile time, and a runtime error at runtime. With Virtual Pascal, you get a runtime error at runtime. Add and call a constructor, and the problem goes away.
So, a warning is not a bad idea (better than a crashing program).
[...]
-fbase-object= -- to add default parent to object without an explicit parent
I think this should probably be avoided. If someone wants something to be his base object, he should be able to say so when declaring the object.
That was my first thought. But if we require explicit base we will break almost every Delphi program in existence...
I think you misunderstood me. In Delphi mode, "TObject" should be the implicit ancestor of all classes, and in OOE mode, "Root" should fill this role. This should not be susceptible to being overridden by a command line switch.
With regard to Root and TObject (OOE and Delphi), I have suggested elsewhere that one could probably be a silent ancestor of the other. In fact, they could be one and the same thing (with names changing, and/or members hidden or revealed depending on Delphi or OOE mode). I am not sure whether this makes any sense ...
Consider the following program:
program tsp; type cl = class of TObject; Ob = class(TObject) end; procedure prp1(c : cl); begin while pointer(c) <> nil do begin writeln(c.classname); c := c.classparent; end; end; procedure prp2(c : cl); begin while true do begin writeln(c.classname); if c = TObject then break; c := c.classparent; end; end; begin prp1(ob); prp2(ob); end .
when run using Free Pascal it prints:
Ob TObject Ob TObject
And it does exactly the same in Delphi and Virtual Pascal.
However, if we add extra parent to TObject the first printouts would change. Note that while prp2 would crash on non-Delphi class, both prp1 and prp2 will work fine if we implement Delphi tree correctly.
In which case, TObject and Root would need to be independent of each other.
The other variants also have drawbacks, that is why I would prefer to leave the choice to programmers.
Yes, the programmers should have the choice - but the question is whether that choice should be exercised in code or at the command line. With regard to default ancestors, I think it would be problematic and error-prone to change default ancestors at the command line.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/