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