Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Delphi object inspector grey some properties?

Tags:

delphi

Recently I found that Delphi object inspector displays some properties in grey. Here is an example:

Object Inspector grayed properties Example

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. But as you can see DSHostname is displayed normally and ProxyHost in grey.

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;
like image 969
Alex Avatar asked Jul 17 '16 12:07

Alex


1 Answers

Finally I got a proof that Remy Lebeau was right in his guess. I made a descendant of TDSClientCallbackChannelManager which has published property TestProxyHost. This property does nothing but mirroring ProxyHost in Get and Set. 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.

In Object Inspector the ProxyHost property is displayed in grey and TestProxyHost as normal. Now if I change TestProxyHost then ProxyHost is changed as well. Here is a screenshot:

ProxyHost property is changed

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.
  2. The only way to achieve such behavior is on the Property Editor level. 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).
  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. 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).

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. And Embarcadero provides no documentation about these properties (at least for now I could not find any). 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.

like image 82
Alex Avatar answered Oct 18 '22 02:10

Alex