惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - Sephil

[小技巧] 倍数的向上取整和向下取整 WTL汉化版 Delphi 与 VC 共享接口和对象 百度音乐下载工具 (最后更新: 2012-7-20) 为Delphi应用增加脚本支持 插件框架Extensible Framework for Delphi DirectUI for Delphi VC CListCtrl 第一列列宽自适应 WriteFile写磁盘扇区是87错误的原因 批量更改文件名的批处理文件 替代Windows运行功能的工具FastRun 关于 API 中返回字串的一些问题 BCB/Delphi2007 隐藏任务栏图标 OGA & WGA Crack 所有小工具 迅雷/快车/旋风地址转换器 oracle ora-01033和ora-00600错误 数独游戏 SudokuPuzzle 将文件夹映射为驱动器的工具
DelphiXE泛型不能用类类型做为约束的另类解决方案
Sephil · 2012-09-06 · via 博客园 - Sephil

前天想写个泛型类,用来保存类类型(如TClass、TComponentClass之类)

但是DelphiXE的泛型约束不支持TClass

TClassList<T: TClass> 将会得到编译错误

因此我只能去掉约束条件 TClassList<T>

但是这样又有个问题,即 T 类型不明确,无法用 Assigned(T) 或 T <> nil 来判断值是否为空

后来想了个办法绕过了这个问题,详见代码

procedure TClassList<T>.Register(const ADisplayName: string; AClass: T);
var
  P: Pointer;
begin
  P := PPointer(@AClass)^;
  Assert(Assigned(P), 'Target class cannot be nil.');

  FClassList.AddObject(ADisplayName, P);
end;

function TClassList<T>.Find(const ADisplayName: stringout Value: T): Boolean;
var
  Index: Integer;
begin
  Assert(ADisplayName <> '''Display name cannot be blank.');

  Index := FClassList.IndexOf(ADisplayName);
  Result := Index >= 0;
  if Result then PPointer(@Value)^ := Pointer(FClassList.Objects[Index]);
end;

记录一下,免得忘记