Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-05

Own component - problem with default published property

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Krzysztof

Hi,

I think this is a bug, but I want to be sure.
Referring to this wiki:
http://wiki.freepascal.org/How_To_Write_Lazarus_Component#Enhancing_mycom.pas I created own control. In constructor I changed Style from default csDropDown to csDropDownList. I published this property, because user can change this value in object inspector. This works fine until user change style back to default csDropDown. In design I see that is changed to csDropDown, but when I run program, style is csDropDownList (which I set in constructor). This problem occur only when I change style back to default, other styles like csSimple or csOwnerDrawFixed works fine. I tested this on other controls with different types (tested on enumtype and integer), same problem - can't change to default in runtime. I created own enum type - same problem, but when property doesn't have default value then I can change to each kind.

Regards, sorry for my english.

Lazarus from SVN, revision 37049M from 2012-04-29
FPC 2.6.0 stable
Ubuntu 12.04 64bit GTK2

Reply by email

cobines
to Krzysztof

If you changed the default you should publish it with:

property Style default csDropDownList;

If property has default value it is not written to LFM, in that case the value is whatever you set in constructor.

cobines

Reply by email

Krzysztof
to cobines

But what if this is subproperty?

For example:

TMyProperty = class(TPersistent)
published
  property SomeValue: TSomeType read FSomeValue write SetSomeValue default sv1
end;

Can I do something like that:

TMyControl1 = class(TControl)
published
  MyProperty.SomeValue default sv2
end;
TMyControl2 = class(TControl)
published
  MyProperty.SomeValue default sv3
end;

Or must I create new descendant of TMyProperty for each control and then change default value of SomeValue property?

2012/5/16 cobines :

Show quoted text 16 lines
If you changed the default you should publish it with: property Style default csDropDownList; If property has default value it is not written to LFM, in that case the value is whatever you set in constructor. -- cobines -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

cobines
to Krzysztof

2012/5/16 Krzysztof :

Or must I create new descendant of TMyProperty for each control and then change default value of SomeValue property?

Yes, I think you have to do this. If you want to have different defaults for the property then you need to make different classes for them.

cobines

Reply by email

Alexander Klenin
to cobines
cobines wrote 7 lines
2012/5/16 Krzysztof : > Or must I create new descendant of TMyProperty for each control and > then change default value of SomeValue property? Yes, I think you have to do this. If you want to have different defaults for the property then you need to make different classes for them.

Yes, this is somewhat annoying. In TAChart I tried to reduce the amount of extra code
by setting the default value in the ancestor class based on RTTI. This way you need not override constructors of descendant properties.

Alexander S. Klenin

Reply by email