Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?)

like image 592
Ian Boyd Avatar asked Sep 09 '14 14:09

Ian Boyd


1 Answers

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.

like image 107
David Heffernan Avatar answered Nov 14 '22 18:11

David Heffernan