最好有通用的属性获取器/设置器在每次访问时执行共同的任务。
该代码在Delphi XE2'E2008不兼容类型'中给出了编译时错误。类似的代码在编译过程中产生内部错误,但从不编译。我会出错还是编译器限制?
type TFoo = class
private
function Get<T>: T;
public
property Bar: Integer read Get<Integer>;
end;
function TFoo.Get<T>: T;
begin
Result := 0;
end;
以下内容在Delphi语言中可能是通用的:
TFooClass<T> = class
TFooRecord<T> = record
TFooInterface<T> = interface
TFooProc<T> = procedure
procedure FooMethod<T>()
属性本身不能是通用的,不能使用通用的getter或setter方法实现。