Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have the read/write of a property to have different visibility?

As the question says... is it possible to declare the read/write of a property at different level of visibility. If so, what would be the syntax?

Something along the line of :

  protected
    property MyProp : Integer write FMyProp;
  public
    property MyProp : Integer read FMyProp;
  end;

Not that it would be a major language feature, it's easily replaced by

protected
  procedure SetMyProp(Value : Integer);
public
  property MyProp : Integer read FMyProp;
end;

I'm just curious if such a possibility exists.

like image 559
Ken Bourassa Avatar asked Apr 01 '11 15:04

Ken Bourassa


2 Answers

No, you have to split it into two separate properties (with different names), although they can refer to the same private field.

like image 115
Ondrej Kelle Avatar answered Oct 11 '22 11:10

Ondrej Kelle


No, this isn't possible. I'm not sure why you would need to do that, however.

The only reason I can see is to make it read-only while still allowing it to be published and seen in the Object Inspector, and you can already do this:

private
  procedure SetMyProp(Value: String);
published
  MyProp: string read FMyProp write SetMyProp;

...
procedure TMyComponent.SetMyProp(Value: String);
begin
  //
end;
like image 20
Ken White Avatar answered Oct 11 '22 13:10

Ken White