[fpc-devel] proposal: Extension for class properties

Alexander Todorov alexx.todorov at gmail.com
Wed May 10 19:00:01 CEST 2006


Hello,
Let's consider the following code fragment:
--------------------------------------------------
type

  TMyRecord = record
     Name : String;
     Value : Integer;
  end;

  TMyClass = class(TObject)
  private
     FButton : TButton;
     FRecord : TMyRecord;
  public
     property RecordName : String read FRecord.Name write
FRecord.Name;    // compiles
     property ButtonWidth: Integer read FButton.Width write
FButton.Width; // does not compile
  end;
--------------------------------------------------

Is it really too hard to make the compiler understand properties with
the second type of declaration as the ButtonWidth example? I would
prefer this to
--------------------------------------------------
property ButtonWidth: Integer read GetButtonWidth write SetButtonWidth;

function <class name>.GetButtonWidth: Integer;
begin
   Result := FButton.Width;
end;

procedure <class name>.SetButtonWidth(const AValue: Integer);
begin
   FButton.Width := AValue;
end;
--------------------------------------------------

Please state your comments on this idea. Is it good or not? Is this
something that you would like to have as a feature? Is it able to be
implemented?
How?
Maybe using hidden Get/Set methods?

Thanks.



More information about the fpc-devel mailing list