Cannot declare default values ​​for string properties

I am writing a component that consists of many properties that should appear in the Delphi IDE object inspector (published properties) ...

type
  TMyComponent = class(TComponent)
  private
    FMyProperty: String;
  published
    property MyProperty: String read FMyProperty write SetMyProperty default 'Something';
  end;

However, this does not allow me to apply the default value to the string property ...

[DCC Error] MyUnit.pas(278): E2146 Default values must be of ordinal, pointer or small set type

All other properties by default work fine (Integer, Enum, etc.).

My goal is to A) not save string properties in DFM if they are the default value, and B) show the value in the Object Inspector as Bold if it is not the default, and correct if. There are over 130 properties that are displayed for this component, and about 50 of them are string properties, some of which have fairly large default values.

string ? Delphi , ?

, , Inno Setup /. Setup, 100 . , 20 , , DFM ( ). , , Inno Setup script.

+3
2

default, . stored, :

type
  TMyComponent = class(TComponent)
  private
    FProp: String;
    function MyPropIsStored: Boolean;
    procedure SetProp(const Value: String);
  public
    constructor Create(AOwner: TComponent); override;
  published
    property MyProp: String read FProp write SetProp stored MyPropIsStored;
end;

constructor Create(AOwner: TComponent); override;
begin
  Inherited;
  FProp := 'my default value';
end;

function TMyComponent.MyPropIsStored: Boolean
begin
  Result := FProp <> 'my default value';
end;
+7

, . default :

  • , DFM ( , Visible), True, DFM, False. (. )

  • , , (, Delphi TList.Items), Items List[x] List.Items[x] .

, Object Inspector, . , , , , DFM.

, (. " " ( ):

default nodefault , 0 31; nodefault, . , 0, nil '' ( ) .

. , Remy. , ( ):

. ( ), , . .

+2

All Articles