Recent

Author Topic: Error: Incompatible types: got "<procedure variable type of function:DWord; ...  (Read 6562 times)

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Hi,

when changing from {$MODE Delphi}  to  {$mode objfpc}{$H+}
I got a curious error message:

gdipobj.pas(6348,14) Error: Incompatible types: got "<procedure variable type of function:DWord;StdCall>" expected "LongWord"


I expected anything else but the wrong code was:
Code: Pascal  [Select][+][-]
  1. Result:= GdipCreateHalftonePalette;

.. and the working code is :
Code: Pascal  [Select][+][-]
  1. Result:= GdipCreateHalftonePalette();
compiler is happy, no errors.


The declared function is:
Code: Pascal  [Select][+][-]
  1.   GdipCreateHalftonePalette : function : HPALETTE; stdcall;
  2.  


Why does the compiler need the brackets ?
usually using latest Lazarus release version with Windows 10

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Yes, this is an objfpc "feature".

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Yes, this is an objfpc "feature".
Hm, maybe it's possible to throw out a more "self-speaking" error description ?  :(
usually using latest Lazarus release version with Windows 10

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Yes, this is an objfpc "feature".
Hm, maybe it's possible to throw out a more "self-speaking" error description ?  :(

Easiest is to just use $mode delphi, and leave the DIY dialect be.
« Last Edit: June 06, 2017, 02:23:24 pm by marcov »

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Easiest is to just use $mode delphi, and leave the DIY dialect be.

Easy, yes, but not a good idea, from my point of view.
Lazarus forces a more strict use of the language.

For example You are not allowed to use
a var name twice in the declaration of

 for example: nativeRegion

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyObject = class(TComponent)  
  3.   protected
  4.     nativeRegion: GpRegion;
  5.     ...
  6.   public
  7.     constructor Create(aNativeRegion: GpRegion); reintroduce; overload;
  8.     ...
  9.   end;
  10.  

When changing from {$MODE Delphi}  to  {$mode objfpc}{$H+}
I found several bugs .. using the local or global var in the wrong way ..

And I already can handle most of the code differences
between Delphi and Lazarus by using lots of $ifdef
« Last Edit: June 06, 2017, 03:23:22 pm by PeterX »
usually using latest Lazarus release version with Windows 10

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
And I already can handle most of the code differences
between Delphi and Lazarus by using lots of $ifdef

That's exactly what I like to avoid. The benefits IMHO don't outweigh that, and the very few bugs that it hypothetically could prevent are mostly also found with static code analysis tools.

code analysis has the disadvantage that it is a second parser/system that must be kept working with the current dialect, but has as advantage that its inner workings are not set in stone for compatibility reasons (Like doing it on language level does)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Just in passing, does the Code Completer not add the "();" if you use the code completion facility?
I find this so much more useful than the Delhi version which was a bit hit-and-miss!
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

PeterX

  • Sr. Member
  • ****
  • Posts: 404
usually using latest Lazarus release version with Windows 10

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Yes plz don't over-use ifdef when it is pointless. Use {$IF defined ()...} 8-) ;D :D
I am with Marco here. Use {$mode delphi}. Quirks mode is for fanatics.
Specialize a type, not a var.

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Yes plz don't over-use ifdef when it is pointless. Use {$IF defined ()...} 8-) ;D :D
I am with Marco here. Use {$mode delphi}. Quirks mode is for fanatics.

English is not my native language.
I am not sure what You want to point out here.

I never used
Code: Pascal  [Select][+][-]
  1. $IF defined () ...

What does it do better than
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC}
???

And what is
Code: Pascal  [Select][+][-]
  1. Quirks mode
??
« Last Edit: June 13, 2017, 11:08:11 pm by PeterX »
usually using latest Lazarus release version with Windows 10

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Quirks mode is short for{$mode objfpc}  :D :D :D

With {$IF Defined()} or {$IF Declared()} you have much more powerful capabilities to prevent a 1000 {$ifdefs} because it allows for boolean arithmetic (and/or/not etc) and even comparison operators like <, >, = etc. based on available information at compile time.
{$ifdef} is just for compatibility with delphi versions below 7 (maybe even 6)
{$IF} is Delphi compatible from D7 and fpc 2

I don't understand all those ifdefs, because you only need to determine with two ifdefs if {$IF} is supported and then basicaly write comparisons with {$IF}. Bad example is jedi.inc.
« Last Edit: June 13, 2017, 11:49:57 pm by Thaddy »
Specialize a type, not a var.

PeterX

  • Sr. Member
  • ****
  • Posts: 404
I don't understand all those ifdefs, because you only need to determine with two ifdefs if {$IF} is supported and then basicaly write comparisons with {$IF}. Bad example is jedi.inc.

Sorry, the project I am working on is/was a Delphi 5 project.
usually using latest Lazarus release version with Windows 10

 

TinyPortal © 2005-2018