Delphi对象检查器如何灰色一些属性?

Ale*_*lex 9 delphi

最近我发现Delphi对象检查器以灰色显示一些属性.这是一个例子:

Object Inspector灰色属性示例

我想知道它是什么意思?如何定义这些属性?我没有发现让我们说DSHostnameProxyHost的定义有任何不同.但正如您所见,DSHostname正常显示,ProxyHost显示为灰色.

以下是相关财产的相关声明:

  /// <summary>The host to proxy requests through, or empty string to not use a proxy.</summary>
  property ProxyHost: string read FProxyHost write FProxyHost;
  /// <summary>The port on the proxy host to proxy requests through. Ignored if DSProxyHost isn't set.
  /// </summary>
  [Default(8888)]
  property ProxyPort: Integer read FProxyPort write FProxyPort default 8888;
  /// <summary>The user name for authentication with the specified proxy.</summary>
  property ProxyUsername: string read FProxyUsername write FProxyUsername;
  /// <summary>The password for authentication with the specified proxy.</summary>
  property ProxyPassword: string read FProxyPassword write FProxyPassword;
Run Code Online (Sandbox Code Playgroud)

Ale*_*lex 5

最后,我得到了一个证据,证明Remy Lebeau的猜测正确.我做了TDSClientCallbackChannelManager的后代,它已经发布了属性TestProxyHost.此属性除了在Get和Set中镜像ProxyHost之外什么都不做.以下是组件的完整代码:

unit uTestCallbackChannelManager;

interface

uses
  System.SysUtils, System.Classes, Datasnap.DSCommon;

type
  TTestCallbackChannelManager = class(TDSClientCallbackChannelManager)
  private
    function GetTestProxyHost: string;
    procedure SetTestProxyHost(const Value: string);
  published
    property TestProxyHost: string read GetTestProxyHost write SetTestProxyHost;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TTestCallbackChannelManager]);
end;

{ TTestCallbackChannelManager }

function TTestCallbackChannelManager.GetTestProxyHost: string;
begin
  Result := ProxyHost;
end;

procedure TTestCallbackChannelManager.SetTestProxyHost(const Value: string);
begin
  ProxyHost := Value;
end;

end.
Run Code Online (Sandbox Code Playgroud)

在我将TTestCallbackChannelManager安装到组件面板后,我将放入测试项目中的表单上.

在Object Inspector中,ProxyHost属性显示为灰色,TestProxyHost正常显示.现在,如果我更改TestProxyHost,那么也会更改ProxyHost.这是一个截图:

ProxyHost属性已更改

这意味着:

  1. ProxyHost属性的RTTI信息没有以任何方式改变,它在设计和运行时确实是读/写属性.
  2. 实现此类行为的唯一方法是在Property Editor级别.该属性编辑器注册了这个特殊的属性名组件类型"讲述"对象检查器"嘿嘿,我不能设置该属性为你"(但在其他代码可以直接做到这一点).
  3. 这也解释了为什么,如果我选中"显示只读属性",在对象检查选项标志的ProxyHost(3个相关的属性)Object Inspector中仍显示.这是因为Object Inspector将dfm中的属性读取为读/写,然后为它们创建属性编辑器,一旦属性编辑器说它无法写入属性,它们将以灰色阴影显示(但仍显示为属性编辑器已创建) .

唯一的问题是属性编辑器背后的逻辑是什么?当属性可用时以及如何使用它们?看起来这些属性最近在xe10或更早版本中引入.Embarcadero没有提供有关这些属性的文档(至少目前我找不到任何文档).但这是一个单独问题的主题.我怀疑对这些属性的支持尚未经过测试(或可能尚未实现),因此它们旨在用于将来的版本中.