简体   繁体   English

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

[英]How Delphi object inspector grey some properties?

Recently I found that Delphi object inspector displays some properties in grey. 最近我发现Delphi对象检查器以灰色显示一些属性。 Here is an example: 这是一个例子:

Object Inspector灰色属性示例

I wonder what does it mean? 我想知道它是什么意思? How such properties are defined? 如何定义这些属性? I did not find any differences in definition of let's say DSHostname and ProxyHost . 我没有发现让我们说DSHostnameProxyHost的定义有任何不同。 But as you can see DSHostname is displayed normally and ProxyHost in grey. 但正如您所见, DSHostname正常显示, ProxyHost显示为灰色。

Here is a relevant declaration of properties in question: 以下是相关财产的相关声明:

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

Finally I got a proof that Remy Lebeau was right in his guess. 最后,我得到了一个证据,证明Remy Lebeau的猜测正确。 I made a descendant of TDSClientCallbackChannelManager which has published property TestProxyHost . 我做了TDSClientCallbackChannelManager的后代,它已经发布了属性TestProxyHost This property does nothing but mirroring ProxyHost in Get and Set. 此属性除了在Get和Set中镜像ProxyHost之外什么都不做。 Here is the full code for the component: 以下是组件的完整代码:

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.

After I installed TTestCallbackChannelManager into component palette I dropped in on a form in a test project. 在我将TTestCallbackChannelManager安装到组件面板后,我将放入测试项目中的表单上。

In Object Inspector the ProxyHost property is displayed in grey and TestProxyHost as normal. 在Object Inspector中, ProxyHost属性显示为灰色, TestProxyHost正常显示。 Now if I change TestProxyHost then ProxyHost is changed as well. 现在,如果我更改TestProxyHost,那么也会更改ProxyHost Here is a screenshot: 这是一个截图:

ProxyHost属性已更改

This means: 这意味着:

  1. RTTI information of ProxyHost property was not altered in any way and it is indeed a read/write property in both design- and run-time. ProxyHost属性的RTTI信息没有以任何方式改变 ,它在设计和运行时确实是读/写属性。
  2. The only way to achieve such behavior is on the Property Editor level. 实现此类行为的唯一方法是在Property Editor级别。 The Property Editor registered for this particular property name in this component type "tells" Object Inspector "Hey, I can not set this property for you" (but an other code can do it directly). 属性编辑器组件类型中注册了此特定属性名称 “tell”对象检查器“嘿,我无法为您设置此属性”(但其他代码可以直接执行此操作)。
  3. This also explains why if I uncheck "Show read only properties" flag in Object Inspector options ProxyHost (and 3 related properties) are still shown in the Object Inspector. 这也解释了为什么如果取消选中Object Inspector选项中的“Show read only properties”标志, ProxyHost (以及3个相关属性)仍会显示在Object Inspector中。 It is because of Object Inspector reads the properties from dfm as read/write and then creates Property Editors for them and once Property Editor says it can't write the property they are shaded in grey (but still shown as Property Editor is already created). 这是因为Object Inspector从dfm中读取属性作为读/写,然后为它们创建属性编辑器,一旦属性编辑器说它无法写入属性,它们以灰色阴影显示(但仍然显示为属性编辑器已创建) 。

The only problem is what logic behind the Property Editor? 唯一的问题是属性编辑器背后的逻辑是什么? When the properties become available and how to use them? 当属性可用时以及如何使用它们? It looks like the properties are introduced very recently in xe10 or a bit earlier. 看起来这些属性最近在xe10或更早版本中引入。 And Embarcadero provides no documentation about these properties (at least for now I could not find any). Embarcadero没有提供有关这些属性的文档(至少目前我找不到任何文档)。 But this is a subject of separate question. 但这是一个单独问题的主题。 I suspect that support for these properties has not been tested (or may be not implemented) yet and so they are intended for use in future releases. 我怀疑对这些属性的支持尚未经过测试(或可能尚未实现),因此它们旨在用于将来的版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM