Using $IF near an attribute results in incorrect behavior

island
(takepoi) #1

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

0 Likes

(RemObjects) #2

Thanks, logged as bugs://82359

0 Likes

(Carlo Kok) #3

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?

0 Likes

(RemObjects) #4

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

0 Likes

(takepoi) #5

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.

0 Likes

(Carlo Kok) #6

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

0 Likes

(takepoi) #7

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.

0 Likes

(Carlo Kok) #8

What am I missing?

0 Likes

(takepoi) #9

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.

0 Likes

(RemObjects) #10

bugs://82359 got reopened.

0 Likes

(Carlo Kok) #11

Got it. Fixed! thanks

1 Like

(RemObjects) #12

bugs://82359 got closed with status fixed.

0 Likes