Delphi Error – E2146 Default values must be of ordinal, pointer or small set type

Delphi Compiler Error

E2146 Default values must be of ordinal, pointer or small set type

Reason for the Error & Solution

You have declared a property containing a default clause, but the type property type is incompatible with default values.

  program Produce;

    type
      VisualGauge = class
        pos : Single;
  property Position : Single read pos write pos default 0.0;
      end;

  begin
  end.

The program above creates a property and attempts to assign a default value to it, but since the type of the property does not allow default values, an error is output.

  program Produce;

    type
      VisualGauge = class
        pos : Integer;
  property Position : Integer read pos write pos default 0;
      end;

  begin
  end.

When this error is encountered, there are two easy solutions: the first is to remove the default value definition, and the second is to change the type of the property to one which allows a default value. Your program, however, may not be as simple to fix; consider when you have a set property which is too large – it is this case which will require you to carefully examine your program to determine the best solution to this problem.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...