[fpc-pascal] Const attributes

Howard Page-Clark hdpc at talktalk.net
Sun Jul 30 21:35:44 CEST 2017


On 30/07/17 19:55, Marcos Douglas B. Santos wrote:
> I would like to instantiate my attribute only once inside constructor
> and then it will be "const" or "final", I mean, immutable.
> Today it is not possible, right? Any thoughts to the future?
It is not what you are asking for, but you can do this:

===code begin===
{$J-}
const
   INT: Integer = 9;

type

   TFoo = class
   strict private
     function GetINT: Integer;
   public
     property INT: Integer read GetINT;
   end;

function TFoo.GetINT: Integer;
begin
   Exit(INT);
end;
===code end===

The INT property is 'immutable' because it is read-only, and you cannot 
assign to its typed integer referent because of the {$J-}.



More information about the fpc-pascal mailing list