[英]is possible to Create Getter Setter as Single Type like(string, integer …etc) with params for property Interface to abbreviate code?
我只是有一个想法想向你建议,也许我们可以在 Delphi 上实现它
我在这里有这个例子:
IMyinterface = Interface ['{0A86FC8C-04F0-4EC8-846A-B8FE9EBFE7A6}']
property Aproperty: TGetterSetter(String, poReadWrite);
end;
实现这个接口的类可以是这样的:
TMyClass = class(TInterfacedObject, IMyinterface)
strict private
FProperty: String;
procedure SetProperty(aProperty: string);
function GetProperty: string;
public
constructor Create(const aProperty: String);
destructor Destroy; override;
end;
在 Create 的实现中:
constructor TMyClass.Create(const aProperty: String);
begin
// here the Type is try to Create it's self (for compiler know exactly what we mean!!)
TGetterSetter.Create(FName, SetProperty, GetProperty);
SetProperty(aProperty);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.