Recent

Author Topic: Does FreePascal have the option of setting a default value for an object field?  (Read 2064 times)

vfclists

  • Hero Member
  • *****
  • Posts: 856
    • HowTos Considered Harmful?
Does FreePascal have the option of setting a default value for an object field?

eg.

Code: [Select]
TType =class (TObject)
  FInteger: integer; default 5
  constructor Create;override;
end;

rather than

Code: [Select]
constructor TType.Create;
begin
  someVar := TType.Create;
  FInteger = 5;
end;
Lazarus 2.1.0/FPC 3.2.0

Cyrax

  • Hero Member
  • *****
  • Posts: 839
That only works for properties. It is needed for persistence. Even then you need to set default value in the class instance constructor.

 

TinyPortal © 2005-2018