Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-05

proposal: Extension for class properties

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Todorov

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.

Reply by email

Michael Van Canneyt
to Alexander Todorov
Alexander Todorov wrote 42 lines
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.

Reply by email