Delphi – E2018 Record, object or class type required

The compiler was looking for a type name that specified a record, object, or class, but none could be found.

 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.

In this application, there are two possible causes for the same error. The first is when you use ‘.’ on something that isn’t a record. In the second scenario, a variable of the wrong type is used 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 simple answer to this problem is to make sure that the ‘.’ and WITH are only used on records, objects, or class variables.