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 X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...