Recent

Author Topic: Inc operator overloading problem with latest FPC  (Read 2259 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Inc operator overloading problem with latest FPC
« Reply #15 on: December 10, 2023, 06:49:31 pm »
No, that is correct, but apply that to tour first example. It will work out of the box.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: Inc operator overloading problem with latest FPC
« Reply #16 on: December 10, 2023, 08:32:12 pm »
then you have this.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$ModeSwitch AdvancedRecords}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  10.  
  11. type
  12.   TTest = record
  13.     I:Integer;
  14.   end;
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     Button1: TButton;
  20.     procedure Button1Click(Sender: TObject);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26. Procedure Inc(Var A:Ttest;B:Integer=1) overload  inline;
  27. Procedure Inc(Var A:Integer;B:Integer=1) overload inline;
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36. Procedure Inc(Var A:Ttest;B:Integer=1);
  37. Begin
  38.   System.Inc(A.I, B);
  39. End;
  40. Procedure Inc(Var A:Integer;B:Integer=1);
  41. Begin
  42.   System.Inc(A, B);
  43. end;
  44.  
  45. procedure TForm1.Button1Click(Sender: TObject);
  46. Var
  47.   A:Ttest;
  48.   B:Integer;
  49. begin
  50.   Inc(B);
  51.   Inc(A);
  52. end;
  53.  
  54. end.
  55.  
  56.  
The only true wisdom is knowing you know nothing

ad1mt

  • Full Member
  • ***
  • Posts: 199
    • Mark Taylor's Home Page
Re: Inc operator overloading problem with latest FPC
« Reply #17 on: December 11, 2023, 10:06:42 am »
then you have this.
Code: Pascal  [Select][+][-]
  1. Procedure Inc(Var A:Integer;B:Integer=1);
  2. Begin
  3.   System.Inc(A, B);
  4. end;
  5.  
Yes, I had thought of that. But I would have re-implement every possible combination of parameter types to Inc, including strings, that the system Inc works with; not just a few integer types.
I think I've decided that the two parameter Inc will not be implemented in my library. They can easily just implement it themselves if they really need it.

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: Inc operator overloading problem with latest FPC
« Reply #18 on: December 11, 2023, 02:53:46 pm »
There is the Coperators when on and normally defaulted as on.

+=. -= etc.

Not sure if you can do those.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018