Sign in Join

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

Mailing lists / fpc-pascal / 2013-03

Is it only properties that can have defaults in type definitions?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Frank Church

Is it only properties that can have defaults in type definitions? ie can private fields be only initialized after creation, eg in the constructor?

Is something like this allowed

TSomeObject = TObject
private
  FBoolean: Boolean default false;
public
  FPublishedBoolean: Boolean read FBoolean write FBoolean default false;
end;
Frank Church ======================= http://devblog.brahmancreations.com
Martin
to Frank Church
Frank Church wrote 14 lines
Is it only properties that can have defaults in type definitions? ie can private fields be only initialized after creation, eg in the constructor? Is something like this allowed TSomeObject = TObject private FBoolean: Boolean default false; public FPublishedBoolean: Boolean read FBoolean write FBoolean default false; end;

"default" does NOT initialize the property.

It is used for streaming. This value will not be wriiten to an lfm for example, and if loaded, then it acts as default

Frank Church
to Martin
Martin wrote 23 lines
On 14/03/2013 15:35, Frank Church wrote: > > Is it only properties that can have defaults in type definitions? > ie can private fields be only initialized after creation, eg in the > constructor? > > Is something like this allowed > > TSomeObject = TObject > private > FBoolean: Boolean default false; > public > FPublishedBoolean: Boolean read FBoolean write FBoolean default false; > end; > > > "default" does NOT initialize the property. It is used for streaming. This value will not be wriiten to an lfm for example, and if loaded, then it acts as default

Can other fields private, protected etc have defaults set for them in the type defintion, or does that have to be only after creation?

Frank Church ======================= http://devblog.brahmancreations.com
Michael Van Canneyt
to Frank Church
Frank Church wrote 27 lines
On 14 March 2013 15:38, Martin wrote: > On 14/03/2013 15:35, Frank Church wrote: >> >> Is it only properties that can have defaults in type definitions? >> ie can private fields be only initialized after creation, eg in the >> constructor? >> >> Is something like this allowed >> >> TSomeObject = TObject >> private >> FBoolean: Boolean default false; >> public >> FPublishedBoolean: Boolean read FBoolean write FBoolean default false; >> end; >> >> >> > > "default" does NOT initialize the property. > > It is used for streaming. This value will not be wriiten to an lfm for > example, and if loaded, then it acts as default > Can other fields private, protected etc have defaults set for them in the type defintion, or does that have to be only after creation?

Default values must always be set in the constructor.

The only thing that is guaranteed is that the instance data is zeroed out.

Michael.