Recent

Author Topic: Ubuntu Lazarus can't compile predefined class with IUnknown interface  (Read 2773 times)

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Hi All

I have next code example

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. //{$mode objfpc}{$H+}
  4. {$MODE Delphi}//{$H+}
  5.  
  6.  
  7. interface
  8.  
  9. uses
  10.   Classes, SysUtils;
  11.  
  12. type
  13.   TEditButtonEh = class;
  14.  
  15. { TEditButtonEh }
  16.  
  17.   TEditButtonEh = class(TCollectionItem {$IFNDEF CIL}, IUnknown {$ENDIF})
  18.   private
  19.   protected
  20.     { IInterface }
  21.   {$IFDEF FPC}
  22.     function QueryInterface(constref IID: TGUID; out Obj): HResult; virtual; stdcall;
  23.   {$ELSE}
  24.     function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
  25.   {$ENDIF}
  26.     function _AddRef: Integer; stdcall;
  27.     function _Release: Integer; stdcall;
  28.   end;
  29.  
  30.  
  31. implementation
  32.  
  33. {$IFDEF FPC}
  34. function TEditButtonEh.QueryInterface(constref IID: TGUID; out Obj): HResult;
  35. {$ELSE}
  36. function TEditButtonEh.QueryInterface(const IID: TGUID; out Obj): HResult;
  37. {$ENDIF}
  38. begin
  39.   if GetInterface(IID, Obj)
  40.     then Result := 0
  41.     else Result := E_NOINTERFACE;
  42. end;
  43.  
  44. function TEditButtonEh._AddRef: Integer;
  45. begin
  46.   Result := -1;
  47. end;
  48.  
  49. function TEditButtonEh._Release: Integer;
  50. begin
  51.   Result := -1;
  52. end;
  53.  
  54. end.
  55.  

Lazarus.Win32 1.8.4 compile this unit without error.

Lazarus.Ubuntu  raise next errors

Compile Project, Target: project1: Exit code 256, Errors: 3
unit2.pas(13,19) Error: No matching implementation for interface method "QueryInterface(constref TGuid;out <Formal type>):LongInt; CDecl;" found
unit2.pas(13,19) Error: No matching implementation for interface method "_AddRef:LongInt; CDecl;" found
unit2.pas(13,19) Error: No matching implementation for interface method "_Release:LongInt; CDecl;" found

I can't understand is this a feature or bug.

I need to have a "forward class declaration" in my big real unit.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Ubuntu Lazarus can't compile predefined class with IUnknown interface
« Reply #1 on: September 05, 2018, 07:47:00 pm »
Hi All

I have next code example

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. //{$mode objfpc}{$H+}
  4. {$MODE Delphi}//{$H+}
  5.  
  6.  
  7. interface
  8.  
  9. uses
  10.   Classes, SysUtils;
  11.  
  12. type
  13.   TEditButtonEh = class;
  14.  
  15. { TEditButtonEh }
  16.  
  17.   TEditButtonEh = class(TCollectionItem {$IFNDEF CIL}, IUnknown {$ENDIF})
  18.   private
  19.   protected
  20.     { IInterface }
  21.   {$IFDEF FPC}
  22.     function QueryInterface(constref IID: TGUID; out Obj): HResult; virtual; stdcall;
  23.   {$ELSE}
  24.     function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
  25.   {$ENDIF}
  26.     function _AddRef: Integer; stdcall;
  27.     function _Release: Integer; stdcall;
  28.   end;
  29.  
  30.  
  31. implementation
  32.  
  33. {$IFDEF FPC}
  34. function TEditButtonEh.QueryInterface(constref IID: TGUID; out Obj): HResult;
  35. {$ELSE}
  36. function TEditButtonEh.QueryInterface(const IID: TGUID; out Obj): HResult;
  37. {$ENDIF}
  38. begin
  39.   if GetInterface(IID, Obj)
  40.     then Result := 0
  41.     else Result := E_NOINTERFACE;
  42. end;
  43.  
  44. function TEditButtonEh._AddRef: Integer;
  45. begin
  46.   Result := -1;
  47. end;
  48.  
  49. function TEditButtonEh._Release: Integer;
  50. begin
  51.   Result := -1;
  52. end;
  53.  
  54. end.
  55.  

Lazarus.Win32 1.8.4 compile this unit without error.

Lazarus.Ubuntu  raise next errors

Compile Project, Target: project1: Exit code 256, Errors: 3
unit2.pas(13,19) Error: No matching implementation for interface method "QueryInterface(constref TGuid;out <Formal type>):LongInt; CDecl;" found
unit2.pas(13,19) Error: No matching implementation for interface method "_AddRef:LongInt; CDecl;" found
unit2.pas(13,19) Error: No matching implementation for interface method "_Release:LongInt; CDecl;" found
emphasis is mine the changes bellow should solve the posted errors.
Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.   TEditButtonEh = class(TCollectionItem {$IFNDEF CIL}, IUnknown {$ENDIF})
  3.   private
  4.   protected
  5.     { IInterface }
  6.   {$IFDEF FPC}
  7.     function QueryInterface(constref IID: TGUID; out Obj): HResult; virtual; {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  8.   {$ELSE}
  9.     function QueryInterface(const IID: TGUID; out Obj): HResult; virtual;
  10.   {$ENDIF}
  11.     function _AddRef: Integer;  {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  12.     function _Release: Integer;  {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  13.   end;
  14.  
  15.  
  16. implementation
  17.  
  18. {$IFDEF FPC}
  19. function TEditButtonEh.QueryInterface(constref IID: TGUID; out Obj): HResult; {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  20. {$ELSE}
  21. function TEditButtonEh.QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
  22. {$ENDIF}
  23. begin
  24.   if GetInterface(IID, Obj)
  25.     then Result := 0
  26.     else Result := E_NOINTERFACE;
  27. end;
  28.  
  29. function TEditButtonEh._AddRef: Integer; {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  30. begin
  31.   Result := -1;
  32. end;
  33.  
  34. function TEditButtonEh._Release: Integer; {$IFDEF WINDOWS}stdcall {$ELSE}CDECL{$ENDIF};
  35. begin
  36.   Result := -1;
  37. end;
  38.  
  39. end.
  40.  

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Ubuntu Lazarus can't compile predefined class with IUnknown interface
« Reply #2 on: September 05, 2018, 07:52:36 pm »
Yes. Thank you.

 

TinyPortal © 2005-2018