[fpc-devel] proposal: Extension for class properties

Michael Van Canneyt michael at freepascal.org
Thu May 11 09:25:52 CEST 2006



On Wed, 10 May 2006, Alexander Todorov wrote:

> 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?

What if FButton is Nil ? What about streaming ?
The record is always known to be there, FButton not...

Michael.



More information about the fpc-devel mailing list