Recent

Author Topic: Why Error: Incompatible type for arg no ?  (Read 1449 times)

svd71

  • New Member
  • *
  • Posts: 29
Why Error: Incompatible type for arg no ?
« on: December 19, 2022, 07:11:03 pm »
Hallo all,

I had tried to adopt the delphi code to Lazarus and got follow missunderstood.


Code: Pascal  [Select][+][-]
  1. unit u_amqp_threads;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils,
  9.   AMQP.Connection, AMQP.Interfaces, AMQP.Classes
  10.   ;
  11.  
  12. type
  13.   TProducerThread = Class(TThread)
  14.   Strict Private
  15.     FAMQP: TAMQPConnection;
  16.     FMaxWork: Integer;
  17.     FSleepMS: Integer;
  18.     Procedure WriteLine( Text: String );
  19.   Protected
  20.     Procedure Execute; Override;
  21.     constructor CreateP( AAMQP: TAMQPConnection; AMaxWork, ASleepMS: Integer );
  22.   End;
  23.  
  24.   T_ConsumerThread = Class(TThread)
  25.   Strict Private
  26.     FAMQP: TAMQPConnection;
  27.     FChannel: IAMQPChannel;
  28.     FList: TStringList;
  29.     Procedure WriteLine( Text: String );
  30.   Protected
  31.     Procedure TerminatedSet; Override;
  32.     Procedure Execute; Override;
  33.     constructor Create( AAMQP: TAMQPConnection; const aList: TStringList );
  34.   End;    
  35. ....
  36.  


Code: Pascal  [Select][+][-]
  1. [code=pascal]unit u_custapp;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, custapp,
  9.   AMQP.Connection, AMQP.Interfaces, AMQP.Classes
  10.   , u_amqp_threads
  11.   ;
  12.  
  13. type
  14.  
  15.   { TAMQPApplication }
  16.  
  17.   TAMQPApplication = class(TCustomApplication)
  18.   protected
  19.     procedure DoRun; override;
  20.   public
  21.     constructor Create(TheOwner: TComponent); override;
  22.     destructor Destroy; override;
  23.     class var AMQPApplication : TAMQPApplication;
  24.     class procedure AppStart;
  25.   public
  26.     mc1, mc2 : TStringList;
  27.     AMQP: TAMQPConnection;
  28.     Producer: TProducerThread;
  29.     Consumer1: T_ConsumerThread;
  30.     Consumer2: T_ConsumerThread;
  31.   end;
  32.  
  33. implementation
  34.  
  35. procedure TAMQPApplication.DoRun;
  36. var
  37.   ErrorMsg: String;
  38. begin
  39.     mc1 := TStringList.create;
  40.     mc2 := TStringList.create;
  41.     Consumer1 := u_amqp_threads.T_ConsumerThread.Create( AMQP, mc1 );
  42.     Consumer2 := u_amqp_threads.T_ConsumerThread.Create( AMQP, mc2 );
  43.     Producer := u_amqp_threads.TProducerThread.Create( AMQP, 2, 10 );
  44.                                                                      
  45. .....
  46.  
[/code]

    Consumer1 := u_amqp_threads.T_ConsumerThread.Create( AMQP, mc1 );
u_custapp.pas(41,68) Error: Incompatible type for arg no. 2: Got "TStringList", expected "QWord"
classes.inc(225,21) Hint: Found declaration: constructor Create(Boolean;const QWord=`4194304`);

    Consumer2 := u_amqp_threads.T_ConsumerThread.Create( AMQP, mc2 );
u_custapp.pas(42,68) Error: Incompatible type for arg no. 2: Got "TStringList", expected "QWord"
classes.inc(225,21) Hint: Found declaration: constructor Create(Boolean;const QWord=`4194304`);

    Producer := u_amqp_threads.TProducerThread.Create( AMQP, 2, 10 );
u_custapp.pas(43,69) Error: Wrong number of parameters specified for call to "Create"
Z:\fpcdelux\fpcsrc\rtl\objpas\classes\classes.inc

It looks, that a compiler try to build the constructor from parent-class(TThread). Tjhe options like 'reintroduce' and 'overload' did not help. What is wrong in the code and how I can fix it?


tetrastes

  • Sr. Member
  • ****
  • Posts: 481
Re: Why Error: Incompatible type for arg no ?
« Reply #1 on: December 19, 2022, 08:35:02 pm »
As I understand it, constructors must be public:
Code: Pascal  [Select][+][-]
  1. unit u_amqp_threads;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils,
  9.   AMQP.Connection, AMQP.Interfaces, AMQP.Classes
  10.   ;
  11.  
  12. type
  13.   TProducerThread = Class(TThread)
  14.   Strict Private
  15.     FAMQP: TAMQPConnection;
  16.     FMaxWork: Integer;
  17.     FSleepMS: Integer;
  18.     Procedure WriteLine( Text: String );
  19.   Protected
  20.     Procedure Execute; Override;
  21.   public
  22.     constructor CreateP( AAMQP: TAMQPConnection; AMaxWork, ASleepMS: Integer );
  23.   End;
  24.  
  25.   T_ConsumerThread = Class(TThread)
  26.   Strict Private
  27.     FAMQP: TAMQPConnection;
  28.     FChannel: IAMQPChannel;
  29.     FList: TStringList;
  30.     Procedure WriteLine( Text: String );
  31.   Protected
  32.     Procedure TerminatedSet; Override;
  33.     Procedure Execute; Override;
  34.   public
  35.     constructor Create( AAMQP: TAMQPConnection; const aList: TStringList );
  36.   End;    
  37. ....
  38.  

And there is typo (CreateP vs Create):
Code: Pascal  [Select][+][-]
  1. type
  2.   TProducerThread = Class(TThread)
  3. .....
  4.     constructor CreateP( AAMQP: TAMQPConnection; AMaxWork, ASleepMS: Integer );
  5.  
  6. ......
  7.  
  8. Producer := u_amqp_threads.TProducerThread.Create( AMQP, 2, 10 );
  9.  

svd71

  • New Member
  • *
  • Posts: 29
Re: Why Error: Incompatible type for arg no ?
« Reply #2 on: December 19, 2022, 08:42:41 pm »
Thank you!

tetrastes

  • Sr. Member
  • ****
  • Posts: 481
Re: Why Error: Incompatible type for arg no ?
« Reply #3 on: December 19, 2022, 08:52:02 pm »
Just in case: I have checked it in Lazarus and have got explicit "Warning: constructor should be public".

 

TinyPortal © 2005-2018