[fpc-devel] [] property overloads

Ryan Joseph genericptr at gmail.com
Mon Jul 8 18:04:24 CEST 2019



> On Jul 8, 2019, at 11:07 AM, Sven Barth via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
> As Pascal does not allow differentiating between result types this indeed needs to be/stay forbidden. 
> 

There actually is a need to distinguish between getters/setters but the way property syntax works we’re forced for the return type to be the same as the input for the setter. This is a problem I faced before where I want the getter to return a pointer but I want the setter to take a direct value.

It could be solved by overloading but the syntax for the setter doesn’t make as much sense.

type
  generic TList<T> = class
    public type
      TReference = ^T;
    private
     function GetValue(index: integer): TReference;
     property Values[index: integer]: TReference read GetValue; default;

     procedure SetValue(index: integer; value: T); 
     property Values[index: integer]: T write SetValue; default;
  end;


Regards,
	Ryan Joseph



More information about the fpc-devel mailing list