考虑以下类型
type
TRecs = array[0..100000] of TRec;
PRecs = ^TRecs;
TRecObject = class
private
fRecs: PRecs;
public
constructor Create;
property Recs: PRecs read fRecs;
end;
我想将TRec设为通用参数。问题是我需要放置在类范围之外。因为像
T<MyType>Object = class
private
fRecs: ^array[0..100000] of MyType;
public
property Recs: ^array[0..100000] of MyType read fRecs
end
不可能。
也不要将PRecs设置为参数,因为实际对象中有与TRec相关的代码。
现代Pascal对象有解决方案吗?如果不是,只是好奇是否有其他通用语言可以解决类似问题?
最佳答案
我不确定是否完全理解您的问题,但我认为您正在寻找类似的内容:
type
TMyObject<T> = class
public
type
PArr = ^TArr;
TArr = array[0..100000] of T;
private
fRecs: PArr;
public
property Recs: PArr read fRecs
end;
就是说,我看不到这堂课的意义。您可以只使用
TList<T>
中的Generics.Collections
。而且,如果需要一个数组,则可以使用动态数组:
TArray<T>
或array of T
(根据需要)。