Recent

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

vfclists

  • Hero Member
  • *****
  • Posts: 825
    • 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;
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4

Cyrax

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