Sign in Join

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

Mailing lists / fpc-devel / 2010-10

property writer can not use baseclass

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Martin

Is there a reason for this:

class TBase
   FBar: TObject;
end;
class TChild(TBase)
   function GetBar: TChildObject; // does just a typecast
   // provide a property Bar to avoid type-casts
   property Bar: TChildObject
     read GetBar
     write FBar; // this doesn't work
end;

I understand there is a rule for property and variable type to match exactly...

But in the above case that rule would not be needed? Since FBar: TOBject is a base class of TChildObject, it can store any object that can be assigned to Bar.

Martin

Reply by email

Alexander Klenin
to Martin
Martin wrote 12 lines
class TBase  FBar: TObject; end; class TChild(TBase)  function GetBar: TChildObject; // does just a typecast  // provide a property Bar to avoid type-casts  property Bar: TChildObject    read GetBar    write FBar; // this doesn't work end;

Delphi compatibility?

Alexander S. Klenin

Reply by email

Martin
to Alexander Klenin
Alexander Klenin wrote 14 lines
On Sun, Oct 17, 2010 at 05:44, Martin wrote: > class TBase > FBar: TObject; > end; > > class TChild(TBase) > function GetBar: TChildObject; // does just a typecast > > // provide a property Bar to avoid type-casts > property Bar: TChildObject > read GetBar > write FBar; // this doesn't work > end; Delphi compatibility?

Its mode objfpc...

It's not a big thing.

It's only about how many extra getter methods you'll end up having in the declaration. And therefore how much extra code one has to read.

Of course on the day you write it => no issue, you know it's a forwarder with no function, you fold it away...
But one day in the future, when you revisit the code..., you will not remember.

Reply by email