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

时间:2016-07-17 12:05:20

标签: delphi

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

Object Inspector grayed properties Example

我想知道它是什么意思?如何定义这些属性?我没有发现let的定义有任何差异,比如说 DSHostname ProxyHost 。但正如您所见, 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;

1 个答案:

答案 0 :(得分: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.

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

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

ProxyHost property is changed

这意味着:

  1. ProxyHost 属性的RTTI信息未以任何方式更改,并且在设计和运行时确实是读/写属性。
  2. 实现此类行为的唯一方法是在属性编辑器级别。在组件类型“中为此特定属性名称注册的属性编辑器告诉”对象检查器“嘿,我无法为您设置此属性“(但其他代码可以直接执行)。
  3. 这也解释了为什么如果取消选中Object Inspector选项中的“显示只读属性”标志, ProxyHost (和3个相关属性)仍显示在对象检查器中。这是因为Object Inspector从dfm中读取属性作为读/写,然后为它们创建属性编辑器,一旦属性编辑器说它无法写入属性,它们以灰色阴影显示(但仍然显示为属性编辑器已创建)
  4. 唯一的问题是属性编辑器背后的逻辑是什么?当属性可用时以及如何使用它们?看起来这些属性最近在xe10或更早版本中引入。 Embarcadero没有提供有关这些属性的文档(至少目前我找不到任何文档)。 但这是一个单独问题的主题。我怀疑对这些属性的支持尚未经过测试(或者可能尚未实施),因此它们将在未来版本中使用。

相关问题