[fpc-pascal] Using properties in interfaces

2011-03-22 Thread 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Using properties in interfaces

2011-03-22 Thread Sven Barth

Am 22.03.2011 10:59, schrieb 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?


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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal