arrays - 类的函数返回一个在类之后声明的数组

标签 arrays delphi delphi-7

我以前不知何故没有处理过这个问题。我有一个类

  TRoom = class
   private
     width, length, X1,X2,Y1,Y2, index: integer;
   public
     function draw: RoomArr;      
     procedure setparam;
     function getparam: integer;
  end;

现在,在这之下,因为 Delphi 7 不能返回 TClass 的数组,我已经声明了这个:
RoomArr = Array of TRoom;

这以某种方式解决了问题。不知道为什么,我只是在互联网上找到了这个解决方案

我在其他功能中使用“RoomArr”,它工作正常,正如预期的那样。
但是由于数组是在类之后声明的(否则它不会知道类 TRoom),TRoom 本身(更准确地说是函数“draw”)不能使用它。

有没有办法绕过这个问题?

提前致谢。

最佳答案

TRoom 的前向声明:

Type
  TRoom = class; // forward declaration

  RoomArr = Array of TRoom;

  TRoom = class
    ...
    function draw: RoomArr;
  end;

forward declaration必须在同一类型部分完成。

关于arrays - 类的函数返回一个在类之后声明的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31411258/

相关文章:

javascript - 对象数组结构和键替换

ruby - 如何在给定数组中的某个元素的情况下找到下一个元素

php - 如何: remove object from array that has certain property value and crete new array as result

python - 在 Python 中读取 Delphi 二进制文件

delphi - 如何在不添加相同数量代码的情况下向表单添加更多对象

delphi - 如何使用delphi访问msxml6中complextype中的粒子?

c++ - 将可变大小的 double 组转换为 wchar_t

rest - Delphi - 如何创建通用 REST 调用

delphi - 删除有关已声明但未使用的符号的编译器警告

Delphi在页面控件中按标签号显示框架