Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-11

FPC's behavior regarding new TObject methods

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth

Hello together!

I've installed FPC 2.4.2 and after reading the page about the changes since 2.4.0, I've compiled Lazarus and noticed a warning in imglist.pp regarding a Equals method (already reported). Now I remembered that http://wiki.freepascal.org/User_Changes_2.4.2#TObject_class_declaration mentions that FPC warns in mode delphi, but generates an error in mode objfpc. So I looked at the top of the unit, but did found "{$mode objfpc}".

Puzzled, I wrote the following test program:

==== source begin ====

program tobjectmethods;
{$mode objfpc}
type
   TTestObject = class
   public
     function ToString: String;
     function Equals(aObject: TObject): Boolean;
   end;
function TTestObject.ToString: String;
begin
   Result := 'FooBar';
end;
function TTestObject.Equals(aObject: TObject): Boolean;
begin
   Result := aObject.ToString = Self.ToString;
end;
begin
end.

==== source end ====

Compiling it with FPC 2.4.2 (and 2.5.1 as well) results only in warnings regarding the methods Equals and ToString and not errors as expected after reading the wiki.

So who is right?
a) the wiki (thus there is a bug in FPC - very bad, because 2.4.2 is already released)
b) the compiler (thus the wiki is wrong)

Regards,
Sven

Reply by email

Paul Ishenin
to Sven Barth
Sven Barth wrote 5 lines
TTestObject = class public function ToString: String; function Equals(aObject: TObject): Boolean; end;

You are just redeclaring the method. Try to add ToString property or declare a ToString argument in some method and you should get an error.

Best regards,
Paul Ishenin.

Reply by email

Michael Van Canneyt
to Sven Barth: Hello together! I've installed FPC 2.4.2 and after reading the page about the changes…
Sven Barth wrote 23 lines
Hello together! I've installed FPC 2.4.2 and after reading the page about the changes since 2.4.0, I've compiled Lazarus and noticed a warning in imglist.pp regarding a Equals method (already reported). Now I remembered that http://wiki.freepascal.org/User_Changes_2.4.2#TObject_class_declaration mentions that FPC warns in mode delphi, but generates an error in mode objfpc. So I looked at the top of the unit, but did found "{$mode objfpc}". Puzzled, I wrote the following test program: ==== source begin ==== ==== source end ==== Compiling it with FPC 2.4.2 (and 2.5.1 as well) results only in warnings regarding the methods Equals and ToString and not errors as expected after reading the wiki. So who is right? a) the wiki (thus there is a bug in FPC - very bad, because 2.4.2 is already released) b) the compiler (thus the wiki is wrong)

The compiler is right. You can always re-introduce methods. But if you call 'TObject.Equals', your (wrongly declared) method will not be called. Standard OOP inheritance/overriding rules.

Michael.

Reply by email

Sven Barth
to Paul Ishenin: You are just redeclaring the method. Try to add ToString property or declare a ToString…
Paul Ishenin wrote 8 lines
13.11.2010 20:19, Sven Barth wrote: > TTestObject = class > public > function ToString: String; > function Equals(aObject: TObject): Boolean; > end; You are just redeclaring the method. Try to add ToString property or declare a ToString argument in some method and you should get an error.

Ahhhh... that explains it. In that case I've misunderstood the wiki entry ^^

Thanks for explaining.

Regards,
Sven

Reply by email

Sven Barth
to Michael Van Canneyt: The compiler is right. You can always re-introduce methods. But if you call…
Michael Van Canneyt wrote 32 lines
On Sat, 13 Nov 2010, Sven Barth wrote: > Hello together! > > I've installed FPC 2.4.2 and after reading the page about the changes > since 2.4.0, I've compiled Lazarus and noticed a warning in imglist.pp > regarding a Equals method (already reported). Now I remembered that > http://wiki.freepascal.org/User_Changes_2.4.2#TObject_class_declaration mentions > that FPC warns in mode delphi, but generates an error in mode objfpc. > So I looked at the top of the unit, but did found "{$mode objfpc}". > > Puzzled, I wrote the following test program: > > ==== source begin ==== > > ==== source end ==== > > Compiling it with FPC 2.4.2 (and 2.5.1 as well) results only in > warnings regarding the methods Equals and ToString and not errors as > expected after reading the wiki. > > So who is right? > a) the wiki (thus there is a bug in FPC - very bad, because 2.4.2 is > already released) > b) the compiler (thus the wiki is wrong) The compiler is right. You can always re-introduce methods. But if you call 'TObject.Equals', your (wrongly declared) method will not be called. Standard OOP inheritance/overriding rules.

As told to Paul I've misunderstood the wiki entry. More precisely the part "identifier". :)

Now the world is beautiful again :P

Regards,
Sven

Reply by email