繁体   English   中英

是否可以使用属性接口的参数将 Getter Setter 创建为单一类型(如(字符串、整数等)以缩写代码?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM