4

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.

Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117
  • 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 Feb 16 '12 at 18:07
  • 1
    Try this question http://stackoverflow.com/questions/2210122/why-are-there-so-many-if-definedclr-in-the-vcl-rtl – RRUZ Feb 16 '12 at 18:25

1 Answers1

0

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.

Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117
  • Presumably it's as I imagined and was done that way to avoid having to write lots of condition code in the VCL source. – David Heffernan Feb 16 '12 at 18:22
  • Exactly David. It seems like a mere transitional hack to have the compiler contain a hard-coded way of accepting exactly the notations present in the VCL for the purposes of supporting VCL.net's requirements, and only the idea of "fewer ifdefs" makes any sense to me either. – Warren P Feb 16 '12 at 19:01