Recent

Author Topic: Class refuses to compile  (Read 2160 times)

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Class refuses to compile
« on: March 11, 2018, 11:11:22 am »
I try to recompile code written by CorpsmanDE for Delphi (pingPong)
I work with Opensuse Linux and Lazarus 1.8.2
I get the following Errors
elements.pas(32,24) Error: Duplicate identifier "Position"
elements.pas(32,24) Hint: Identifier already defined in elements.pas at line 29
elements.pas(32,34) Error: Duplicate identifier "SpeedVektor"....etc
Here is the code
Code: Pascal  [Select][+][-]
  1. Unit Elements;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   classes, LCLIntf, LCLType, LCLProc, // Trect
  7.   graphics; // TCanvas, TColor
  8.  
  9.  
  10. Type
  11.   TBall = Class;
  12.  
  13.   TFpoint = Record
  14.     x, y: Single;
  15.   End;
  16.  
  17.  
  18.   TBall = Class
  19.   private
  20.     fvx, fvy, fx, fy, fr, fm: Single;
  21.     fc: Tcolor;
  22.     Function getpos: Tfpoint;
  23.     Procedure Setpos(Value: TFpoint);
  24.     Function getSpeed: Tfpoint;
  25.     Procedure SetSpeed(Value: TFpoint);
  26.   public
  27.     Property Color: Tcolor read FC write fC;
  28.     Property Radius: Single read fr;
  29.     Property Position: Tfpoint read getpos write Setpos;
  30.     Property SpeedVektor: TFpoint read getSpeed write SetSpeed;
  31.     Property Mass: Single read Fm write fm;
  32.     Constructor Create(Position, SpeedVektor: TFpoint; Radius, Mass: single);
  33.     Destructor Destroy; override;
  34.     Procedure Render(Const Canvas: TCanvas);
  35.     Procedure CalculateMass;
  36.     Procedure BorderCollision(CollisionRect: Trect; InsideCollision: Boolean = True);
  37.     Procedure CollideWithOther(Const Ball2: TBall);
  38.     Procedure Move;
  39.   End;
  40.  
  41.  
  42. Function Point(x, y: Single): Tfpoint;
  43. Function Rect(ALeft, ATop, ARight, ABottom: Integer): Trect;
  44.  
  45. Implementation          
Why does the class not compile? What did I wrong?Iassume it compiled in delphi
Thans for the help

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Class refuses to compile
« Reply #1 on: March 11, 2018, 11:18:15 am »
I try to recompile code written by CorpsmanDE for Delphi (pingPong)

To compile delphi code, enable Delphi mode in compiler options, or pass -Sd on the commandline. (or put {$mode delphi} in code). The default is FPC's slightly deviating objfpc dialect
 

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Class refuses to compile
« Reply #2 on: March 11, 2018, 11:18:30 am »
Add {$Mode Delphi} (directly below the unit declaration).
Default compiler mode does not allow the uses af a method parameter that has the same name as an already declared identifier.

Alternatively rename the parameters:
Code: Pascal  [Select][+][-]
  1.   Constructor Create(APosition, ASpeedVektor: TFpoint; ARadius, Mass: single);

Bart

[Edit] Marcov beat me by 15 seconds  >:D

jcaser1948

  • Jr. Member
  • **
  • Posts: 68
Re: Class refuses to compile
« Reply #3 on: March 11, 2018, 01:02:47 pm »
Thanks, it works both ways

 

TinyPortal © 2005-2018