Jump to content
chkaufmann

Default for published property

Recommended Posts

I have a custom control and defined the following published properties:

 

    property MaxValue: Integer read FMaxValue write SetMaxValue default High(Integer);
    property MinValue: Integer read FMinValue write SetMinValue default Low(Integer);

It works fine for MaxValue, but for MinValue I always get this in my dfm files:

 

      MinValue = -2147483648


 

Are there limitations for default values and if yes, where can I find these?

 

Christian

 

Share this post


Link to post

Low(Integer) - assuming 32-bit Integer - will always be -2,147,483,648

What value were you expecting to see? Zero?  Then you need to use Default 0 - or type Cardinal instead of Integer.

Note that using a Cardinal can introduce challenges with regards to math operations that may cause a signed result such as (Small.Minvalue - Big.MinValue) < 0

Share this post


Link to post

I except the default not to be written to the DFM at all. It works for High(Integer) but it looks like it doesn't for Low(Integer).

 

Christian

Share this post


Link to post

The TypeInfo uses the value $80000000 to indicate that this property has no default value.

That unfortunately overlaps with Low(Integer).

 

You have to use the stored keyword:

 

property MinValue: Integer read FMinValue write SetMinValue stored IsMinValueStored;

function TMyComponent.IsMinValueStored: Boolean;
begin
  Result := FMinValue <> Low(Integer)
end;

 

Edited by Stefan Glienke
  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×