4
votes

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.

1
My guess is that the 2009 Win32 compiler understands the attributes syntax since the .net compiler was already in existence. But the 2009 Win32 compiler just ignores the attributes. That same code is also compiled into the .net parts of IDE and for those parts the attributes do have meaning. - David Heffernan

1 Answers

0
votes

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.