How to conditionally save a property in DFM or not?

I have a couple of components, one of the components is β€œbound” to the other, setting the property. For example...

type
  TMain = class(TComponent)
  ...
  published
    property Default: Integer read FDefault write SetDefault;
  end;

  TSub = class(TComponent)
  ...
  published
    property Value: Integer read GetValue write SetValue;
    property Main: TMain read FMain write SetMain;
  end;

So, in the object inspector for, the TSubuser would choose TMainto contact him.

In the subcomponent, I have a property Valuewith both a getter and an installer. If the value of the subcomponent is set to 0, then the recipient receives the property Defaultfrom TMainto which it is bound ...

function TSub.GetValue: Integer;
begin
  if FValue = 0 then begin
    if Assigned(FMain) then begin
      Result:= FMain.Default;
    end else begin
      Result:= 0;
    end;
  end else begin
    Result:= FValue;
  end;
end;

This is done by the object inspector (and therefore its self property) returns the default value from the main, and not to the set value 0.

, , TSub DFM, , 0 ( , ). DFM , , sub, , .

, default 0;, , , 0, DFM. , ( , ).

TSub not DFM, 0 getter ?

+4
1
property Value: Integer read GetValue write SetValue stored IsValueStored;

function TSub.IsValueStored: Boolean;
begin
  Result := (FValue <> 0) or (FMain = nil);
end;

.

+7

All Articles