首页 > 解决方案 > Delphi,由于 E2029 无法创建类

问题描述

这是我的代码:

program FirstProject;

{$APPTYPE CONSOLE}

{$R *.res}

//Implementation

uses
  Classes, System.SysUtils;

type
  TPerson = class
  public
    name: string;
    age: integer;
    constructor Create(newName: string; newAge: integer);
  end;

implementation

constructor TPerson.Create(newName: string; newAge: integer)
begin

end;

当我到达implementation它时,它向我显示了这个错误:

预期声明但发现执行

我怀疑这很简单,但我无法弄清楚。

标签: delphi

解决方案


存在三个问题:

  1. implementation应该被删除。programs 没有interfaceimplementation部分,只有units 有。
  2. 构造函数定义的第一行缺少分号。
  3. 缺少程序的主体。

这是固定版本:

program FirstProject;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Classes, System.SysUtils;

type
  TPerson = class
  public
    name: string;
    age: integer;
    constructor Create(const newName: string; newAge: integer);
 end;

constructor TPerson.Create(const newName: string; newAge: integer);
begin

end;

begin
  // Write your program here.
end.

推荐阅读