用Pascal创建类

用Pascal创建类,pascal,freepascal,Pascal,Freepascal,我试图用Pascal创建一个类,我对声明和语法有点困惑。最主要的是一个错误,我正在向前声明未解决Tetromino.RotateLongInt,我读到我需要在实现部分声明我的过程,但我不确定我要把它放在哪里。另外,如果你注意到我的班级声明还有什么问题,请告诉我 program Tetris; {$MODE OBJFPC} uses crt, sysutils; type Tetromino = class private TempFace : arra

我试图用Pascal创建一个类,我对声明和语法有点困惑。最主要的是一个错误,我正在向前声明未解决Tetromino.RotateLongInt,我读到我需要在实现部分声明我的过程,但我不确定我要把它放在哪里。另外,如果你注意到我的班级声明还有什么问题,请告诉我

program Tetris;
{$MODE OBJFPC}
uses crt, sysutils;
type 
    Tetromino = class
    
    private
        TempFace : array [0..15] of char;       
    public
        Face : array[0..15] of char;
        //constructor create();  (idk what this is but read somewhere that you need it)
        procedure Rotate(rotation : integer);
    end;
var
    a,b,c,d,e,f,g : tetromino;
begin
    ReadKey();
end. 

在程序模块中,不需要划分接口和实现。因此,实现部分中实现过程的错误描述有点误导。尽管如此,它仍然表明缺少旋转过程的实现

因此,错误在于您在Tetromino类中声明了一个过程,但是缺少该过程的实现。您需要在类声明和begin之间的某个地方实现它。。程序的结束块

在具有命名部分:接口和实现的单元模块中,如果要从其他模块访问这些类,请在接口部分声明这些类,并在实现部分实现它们

下面我将概述您需要在程序中执行的操作,包括Tetromino的构造函数


实现是模块的代码部分。在主模块中,程序/函数/方法的实现可以放在第一次开始之前的任何地方。哇,我真傻。我不敢相信我没有发现,我查到了错误,有问题的人正在一个单元中创建一个类,因此我认为我需要使用实现,谢谢。@ChibiAyano欢迎你。顺便说一句,看看你的问题记录,我注意到你没有接受任何关于你的问题的答案,尽管其中有几个值得接受。您可以通过单击最佳答案旁边的勾号接受答案,使其变为绿色。请阅读
program Tetris;
{$MODE OBJFPC}
uses crt, sysutils;
type 
    Tetromino = class
    private
        TempFace : array [0..15] of char;       
    public
        Face : array[0..15] of char;
        constructor create();  (idk what this is but read somewhere that you need it)
        procedure Rotate(rotation : integer);
    end;

var
    a,b,c,d,e,f,g : tetromino;

constructor Tetromino.create;
begin
  // constructor (automatically) aquires a block of memory
  // to hold members of the class
  // to do: initialize member fields of the instance
end;

procedure Tetromino.Rotate(rotation: Integer);
begin
  // implementation of the Rotate() method
end;

begin
    ReadKey();
end.