什么是类帮助器的好用途? [英] What are good uses for class helpers?
本文介绍了什么是类帮助器的好用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Delphi(可能还有很多其他语言)有类助手。这些提供了一种向现有类添加额外方法的方法。
解决方案
我正在使用它们:
- 至将枚举器插入到不实现它们的VCL类中。 / li>
- 要增强 VCL
要向TStrings类添加方法,以便可以在我的派生列表和在TStringList中。
TGpStringListHelper = class helper for TStringList
public
function Last:string;
function Contains(const s:string):boolean;
function FetchObject(const s:string):TObject;
procedure Sort;
procedure Remove(const s:string);
end; {TGpStringListHelper}
要简化对记录字段和删除投射。
Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass.
So, what are good uses for class helpers?
解决方案
I'm using them:
- To insert enumerators into VCL classes that don't implement them.
- To enhance VCL classes.
To add methods to the TStrings class so I can use the same methods in my derived lists and in TStringList.
TGpStringListHelper = class helper for TStringList public function Last: string; function Contains(const s: string): boolean; function FetchObject(const s: string): TObject; procedure Sort; procedure Remove(const s: string); end; { TGpStringListHelper }
To simplify access to record fields and remove casting.
这篇关于什么是类帮助器的好用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文