Delphi 2009 RTL/VCL 中的属性语法?

发布于 2025-01-06 02:47:31 字数 683 浏览 1 评论 0原文

在我工作的地方,我们仍在使用 Delphi 2009。我碰巧在查看 VCL 中的 Forms 单元并偶然发现:

[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
function DisableTaskWindows(ActiveWindow: HWnd): TTaskWindowList;

这个属性显然是 CLR 类 UIPermissionAttribute与其他引用不同CLR 此属性未包装在条件编译指令中。

这让我感到惊讶,因为据我所知,在 2010 年之前的 Delphi Win32 版本中,括号仅用于数组和集合类型中的索引表示法、定义集合并将 GUID 分配给接口。事实似乎并非如此。

我进行了正则表达式搜索,并在整个 RTL/VCL 中找到了数十个示例。有些是类型的属性,有些是方法的属性。

这些是简单地被编译器忽略还是它们在 Win32 中具有某种用途?


我还发现语法如下:

[!UnitName]
[!InterfaceName]

这似乎与从 IDE 向导中的模板生成源文件有关,但这些文件不在 RTL 源文件夹中。它们位于对象存储库文件夹中。

Where I work we're still using Delphi 2009. I happened to be looking at the Forms unit in the VCL and stumbled upon:

[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
function DisableTaskWindows(ActiveWindow: HWnd): TTaskWindowList;

This attribute is clearly the CLR class UIPermissionAttribute but unlike other references to the CLR this attribute is not wrapped in conditional compilation directives.

This surprised me because, AFAIK, in Delphi Win32 versions prior to 2010 brackets were only used for index notation in arrays and collection types, defining sets and assigning GUIDs to interfaces. This doesn't appear to be the case.

I did a regex search and found dozens of examples throughout the RTL/VCL. Some were attributes on types and some on methods.

Are these simply ignored by the compiler or do they serve some purpose in Win32?


I also found syntax that looked like:

[!UnitName]
[!InterfaceName]

Which appears to have something to do with generating source files from a template in an IDE wizard but these weren't in the RTL source folder. They were in the object repository folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抠脚大汉 2025-01-13 02:47:31

我曾希望属性可能是一个未记录的功能,类似于类助手在被记录之前多年的可用方式,但情况似乎并非如此。

我尝试了一个简单的测试,并在类定义之前添加了属性符号。编译器并没有卡住它,但它确实发出了不支持自定义属性的警告。

I had hoped that perhaps attributes were an undocumented feature similar to how class helpers were available for years before they were documented but that doesn't appear to be the case.

I tried a simple test and added attribute notation before a class definition. The compiler didn't choke on it but it did issue a warning that custom attributes aren't supported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文