Delphi Error – E2018 Record, object or class type required

Delphi Compiler Error

E2018 Record, object or class type required

Reason for the Error & Solution

The compiler was expecting to find the type name which specified a record, object or class but did not find one.

  program Produce;

    type
      RecordDesc = class
        ch : Char;
      end;

    var
      pCh : PChar;
      r : RecordDesc;

    procedure A;
    begin
      pCh.ch := 'A';    (* case 1 *)

      with pCh do begin (* case 2 *)
      end;
    end;
  end.


There are two causes for the same error in this program. The first is the application of ‘.’ to a object that is not a record. The second case is the use of a variable which is of the wrong type in a WITH statement.

  program Solve;

    type
      RecordDesc = class
        ch : Char;
      end;

    var
      r : RecordDesc;

    procedure A;
    begin
      r.ch := 'A';    (* case 1 *)

      with r do begin (* case 2 *)
      end;
    end;
  end.

The easy solution to this error is to always make sure that the ‘.’ and WITH are both applied only to records, objects or class variables.

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...