delphi - 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
它时,它向我显示了这个错误:
预期声明但发现执行
我怀疑这很简单,但我无法弄清楚。
解决方案
存在三个问题:
implementation
应该被删除。program
s 没有interface
和implementation
部分,只有unit
s 有。- 构造函数定义的第一行缺少分号。
- 缺少程序的主体。
这是固定版本:
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.
推荐阅读
- c# - “For”循环 - 使用 PropertyInfo 为属性赋值
- javascript - 是否可以从 Javascript(浏览器)更改系统日期?
- powershell - 如何将值用作变量?
- javascript - 在 NuxtJS 中初始加载后,SSR 是如何工作的?
- c# - 以编程方式编辑模板后,如何从 template.xlsx 保存 .xlsx 文件的多个副本(1000 个)
- javascript - 是否有 jquery 函数的 javascript 来禁用或删除 html 视频中的计时器
- performance - 计算没有循环的时间窗口的观察次数
- awk - 无法打开管道太多打开的文件
- excel - Excel VBA 将大于更改为小于会导致运行时错误 1004
- android - 锁屏触发不同activity的应用生命周期事件