如何声明包含使用记录作为参数的事件的记录 [英] How to declare record containing events which use record as parameter
问题描述
我试图找出如何声明一个使用对方的记录和一些对象事件。问题不管我声明什么,我有一个未声明的标识符。
I'm trying to figure out how to declare both a record and a number of object events which use each other. The problem is no matter which way I declare them, I have an "undeclared identifier".
所以使用下面的代码,我可以让他们互相使用吗?事件将被用在一个对象中,并且该记录将被传递给对象的构造函数。
So with the code below, can I get them to use each other? The events will be used in an object, and the record will be passed and used into the object's constructor.
TMyEvent = procedure(Sender: TObject; var Rec: TMyRecord) of object;
TMyRecord = record
OnMyEvent: TMyEvent;
end;
这可能吗?它需要在所有版本的Delphi 7和更高版本中工作。
Is this possible? It needs to work in all versions of Delphi 7 and up.
推荐答案
不幸的是,转发声明只允许用于类而不是记录,所以我知道的唯一方式是使用指针:
Unfortunately forward declarations are only allowed for classes but not records, so the only way I know of is to use pointers:
PMyRecord = ^TMyRecord;
TMyEvent = procedure(Sender: TObject; Rec: PMyRecord) of object;
TMyRecord = record
OnMyEvent: TMyEvent;
end;
这篇关于如何声明包含使用记录作为参数的事件的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!