Sign in Join

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

Mailing lists / fpc-pascal / 2011-03

Using properties in interfaces

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Michael Fuchs

Hello,

if I understand the documentation correct, this is the only way using a property in an interface:

   IMyInterface = interface
     function GetTag: Integer;
     procedure SetTag(AValue: Integer);
     property Tag: Integer read GetTag write SetTag;
   end;

Or exists a possibilty to define the interface like that:

   IMyInterface = interface
     property Tag: Integer;
   end;

And the programmer who implement this interface could decides how to implement the property?

regards
Michael

Sven Barth
to Michael Fuchs
Michael Fuchs wrote 20 lines
Hello, if I understand the documentation correct, this is the only way using a property in an interface: IMyInterface = interface function GetTag: Integer; procedure SetTag(AValue: Integer); property Tag: Integer read GetTag write SetTag; end; Or exists a possibilty to define the interface like that: IMyInterface = interface property Tag: Integer; end; And the programmer who implement this interface could decides how to implement the property?

Not as I'm aware of, because without that the compiler wouldn't be able to call "code" behind the property (even if it's only a field). While this could be worked around in the compiler if the implementation is in the same binary, it's impossible if you use interfaces across DLL boundaries where you don't have (by definition) access to the source (it could even be done in a different language...).

Regards,
Sven