Vcl.Printers.pas(888): W1025 Unsupported language feature: 'custom attribute'
Asked Answered
S

1

14

I'm trying to fix another VCL bug; this time in Vcl.Printers.pas.

For now we are doing this by copying the buggy VCL source files to another folder in the Delphi library path, and applying fixes to those files. We applied the fix to TPrinter.SetPrinter.

But there are six methods in the file that are decorated with attributes:

[PrintingPermission(SecurityAction.LinkDemand, Level=PrintingPermissionLevel.AllPrinting)]
procedure TPrinter.Abort;
begin
   ...

 

[PrintingPermission(SecurityAction.LinkDemand, Level=PrintingPermissionLevel.AllPrinting)]
procedure TPrinter.EndDoc;
begin
   ...

 

[PrintingPermission(SecurityAction.LinkDemand, Level=PrintingPermissionLevel.AllPrinting)]
procedure TPrinter.NewPage;
begin
   ...

 

[PrintingPermission(SecurityAction.LinkDemand, Level=PrintingPermissionLevel.AllPrinting)]
{$IF DEFINED(CLR)}
procedure TPrinter.SetPrinter(ADevice, ADriver, APort: string; ADeviceMode: IntPtr);
{$ELSE}
procedure TPrinter.SetPrinter(ADevice, ADriver, APort: PChar; ADeviceMode: THandle);
{$ENDIF}
var
   ...

 

[PrintingPermission(SecurityAction.LinkDemand, Level=PrintingPermissionLevel.AllPrinting)]
function SetPrinter(NewPrinter: TPrinter): TPrinter;
begin
   ...

Each of these methods causes a warning:

  • [dcc32 Warning] Vcl.Printers.pas(968): W1025 Unsupported language feature: 'custom attribute'
  • [dcc32 Warning] Vcl.Printers.pas(978): W1025 Unsupported language feature: 'custom attribute'
  • [dcc32 Warning] Vcl.Printers.pas(1015): W1025 Unsupported language feature: 'custom attribute'
  • [dcc32 Warning] Vcl.Printers.pas(1026): W1025 Unsupported language feature: 'custom attribute'
  • [dcc32 Warning] Vcl.Printers.pas(1080): W1025 Unsupported language feature: 'custom attribute'
  • [dcc32 Warning] Vcl.Printers.pas(1599): W1025 Unsupported language feature: 'custom attribute'

I could just remove the attributes. Or presumably there is a way to suppress the warnings. But i assume attributes added by Embarcadero have some purpose.

  • What is the way to make the language support the feature custom attributes?
  • Why is it not a warning in the VCL source?
  • Why is VCL source allowed to use it when i'm not?
  • What are these attributes doing?
  • Who reads these attribues?
  • Are there issues with removing them?
  • If there are no issues with removing them, why are they there?

I'm really asking:

How do i make it work?

But i'd also love to know:

Why is it not working?

And the why makes it a much more useful question, but the fix it would be good.

Bonus Chatter

Yes, we eventually plan to think about the possibility of investigating the use of detours. Although presumably the detoured method should still have the attribute (otherwise why would the attribute exist?)

Syncopate answered 9/9, 2014 at 14:1 Comment(4)
+1 nice question, I've never really thought about what these warnings mean until now, thanksTrifocals
Btw, does this mean that we are at an end of your D5 questions?!! If so, then I find myself surprisingly wistfully sad.... ;-)Trifocals
@DavidHeffernan Four weeks into trying to get software to run in XE6. No guarantees that we won't be going back!Syncopate
@DavidHeffernan Eight months into trying to get software to run in XE6. No guarantees that we won't be going back!Syncopate
T
20

The error message is a little misleading. I'll try to translate for you. When the compiler says:

Unsupported language feature: 'custom attribute'

what it really means is:

Cannot find a class, derived from TCustomAttribute, that matches the attribute name that you specified.


These PrintingPermission attributes, which are defined by the .net framework, have meaning for the Delphi .net compiler. Which is still used by Embarcadero to build portions of the IDE. Hence the retention of the conditional code which switches on the presence of the CLR define. When this VCL unit is compiled by the Delphi .net compiler, the compiler can see the .net framework class System.Drawing.Printing.PrintingPermissionAttribute.

There's little to be gained by you trying to deal with warnings in VCL units. It's not your code, and your goal when modifying a VCL unit is to get in and out as quickly as possible. You should be aiming to make the smallest change possible.

So, ignore the warnings. Suppress warnings and hints for the VCL units that you modify. Stuff {$W-} at the top of any VCL units you compile, and move on. Or if you just cannot bring yourself to be quite so draconian, you could use {$WARN UNSUPPORTED_CONSTRUCT OFF}.


Taking your questions in turn:

What is the way to make the language support the feature custom attributes?

It's not a language limitation. It's just that these attributes are only defined when targeting .net.

Why is it not a warning in the VCL source?

It is, at least when compiling for a target other than .net.

Why is VCL source allowed to use it when i'm not?

You would be allowed to use them too if you use the .net compiler.

What are these attributes doing?

System.Drawing.Printing.PrintingPermissionAttribute

Who reads these attribues?

The .net framework. I guess.

Are there issues with removing them?

It won't affect the output produced by the Windows compilers. It will increase the volume of differences in your revision control system.

If there are no issues with removing them, why are they there?

Because they are used on .net.

Trifocals answered 9/9, 2014 at 14:12 Comment(2)
It's nice to have reassurrance that i'm not crazy. But how did you figure this out? How did you know that Bo..Code...Embarcadero compiles Delphi with a .NET compiler?Syncopate
They've stated that the IDE has dependencies on the .net compiler in the past. Can't find it, but it's been blogged about, commented on forum. As for the rest, I just worked it out by a bit of intuition and a spot of Googling for the attribute.Trifocals

© 2022 - 2024 — McMap. All rights reserved.