Using $IF near an attribute results in incorrect behavior

Hi.

[DllExport(‘TestFunc’)]
{$IF NOT WINDOWS}
[CallingConvention(CallingConvention.Cdecl)]
{$ENDIF}
class method TestFunc: LongInt;

This way, the DllExport attribute does not work and the function is not exported.
And also,

{$IF WINDOWS}
[DllExport(‘TestFunc’)]
{$ELSE}
[DllExport(’_TestFunc’)]
[CallingConvention(CallingConvention.Cdecl)]
{$ENDIF}
class method TestFunc: LongInt;

This way too, Windows is the target but the first DllExport attribute does not work.
I think that probably the same problem will occur with other attributes as well as DllExport.

Elements version 10.0.0.2385

Thanks, logged as bugs://82359

Can you tell me what goes wrong? If I do:

unit issue82359_iftest;
interface

[DllExport('TestFunc')]
{$IF NOT WINDOWS}
[CallingConvention(CallingConvention.Cdecl)]
{$ENDIF}
 method TestFunc: LongInt; begin end;

{$IF WINDOWS}
[DllExport('TestFunc2')]
{$ELSE}
[DllExport('_TestFunc2')]
[CallingConvention(CallingConvention.Cdecl)]
{$ENDIF} 
 method TestFunc2: LongInt; begin end;

implementation

begin
    
end.

it exports:

which seems to be right?

bugs://82359 got closed with status cannotrepro (Will reopen if needed)

Write the method in the implementation section.
In the interface section, I could not write a var declaration like Delphi.

method TestFunc: LongInt;
var
l_var: LongInt;
begin
end;

Therefore, I moved the method to the implementation section.

Right but that would not have effect on the actual code generation. Can you should an example of what doesn’t work?

The problem is reproduced if you write the method in the implementation section.

If you write it in the interface section, there is no problem.

What am I missing?

Attributes are also write in the implementation section.

For example,

namespace test;
interface

implementation

[DllExport]
{$IF NOT WINDOWS}
[CallingConvention(CallingConvention.Cdecl)]
{$ENDIF}
method TestFunc: LongInt;
begin
end;
end.

bugs://82359 got reopened.

Got it. Fixed! thanks

1 Like

bugs://82359 got closed with status fixed.