Jak ustawić property typu wyliczeniowego własnego komponentu

0

TStringGridEx to komponent który piszę.
Chiałbym aby po położeniu na formę TStringGridEx miał od razu zaznaczone na True Option.goFixedRowClick.

Standardowo wygląda to tak:
standardowo.jpg

Używając:

type
  TStringGridEx = class(TStringGrid)
    property Options default [goFixedRowClick];
  end;

ustawia wartość domyślną dla goFixedRowClick na False;

pozmianie.jpg

Jak ustawić tą opcję na true?

2

Z głowy nie pamiętam ale wiem, że miałem kiedyś podobny problem i rozwiązałem go za pomocą stored zamiast default
czyli coś mniej więcej takiego (udało mi się wygooglować)

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

Ok. Poradziłem sobie. Kluczem było nadpisanie konstruktora:

type
  TStringGridEx = class(TStringGrid)
  public
    constructor Create(AOwner: TComponent); override; // <<==== brak tego override'a był problemem
  published
    property Options default [goFixedRowClick];
  end;

constructor TStringGridEx.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Self.Options := Self.Options + [goFixedRowClick];
end;
2

default jest do czegoś innego niż nadawanie wartości domyślnej! Nie chce mi się tłumaczyć

The default directive merely tells the compiler whether or not to store the current value of a published property in the associated *.dfm file. It does not actually initialize the property to that value. The default value must be assigned in the constructor.

1 użytkowników online, w tym zalogowanych: 0, gości: 1