开发者

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 lev开发者_JS百科el 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.


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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜