[Lazarus] Different "default" value for a property in derived class
Bart
bartjunk64 at gmail.com
Sat Apr 6 16:09:37 CEST 2013
Hi,
Consider this.
type
TSomeType = (stA, stB, stC);
{ TA }
TA = class
private
FFoo: TSomeType;
public
constructor Create; virtual;
published
property Foo: TSomeType read FFoo write FFoo default stA;
end;
{ TB }
TB = class(TA)
public
constructor Create; override;
end;
implementation
{ TB }
constructor TB.Create;
begin
inherited Create;
Foo := stB;
end;
{ TA }
constructor TA.Create;
begin
FFoo := stA;
end;
Now imagine that you drop an instance ot TB on a form.
In OI you set Foo to stA.
You build and run, and to your surprise Foo is stB.
You think for a while and realize what happened: since property TA.Foo
is declared with "default stA", this means that if you set Foo in OI
to stA it is not streamed to the LFM.
So far, so good.
Now the question: is there any other way to fix this besides removing
the "default stA' from the declaration of the TA.Foo property?
(Assuming that it is necessary for TB to set Foo to stB by default).
Bart
More information about the Lazarus
mailing list