Help needed with operator overloading with advanced records lazarus / 62-General ---------------------------------------------------------------------- ad1mt · 2024-02-09 18:43 I'm having trouble with operator overloading with advanced records. I've read the documentation and the "Object Pascal Handbook" by Marco Cantu (although its possible I may not have understood it correctly  ) I've been able to get it working in {MODE DELPHI} but not in {MODE OBJFPC} with {$MODESWITCH ADVANCEDRECORDS} where I'm getting errors like "Impossible operator overload". Here is an example program, that shows the problem: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$MODE OBJFPC}{$MODESWITCH ADVANCEDRECORDS}// {$MODE DELPHI} program test_extended_record_2;typeT_R = record        R_Val:int64;      public        class operator :=(const v:int64):T_R;        class operator add(const v1,v2:T_R):T_R;      end;varv1,v2,v3:T_R; class operator T_R.:=(const v:int64):T_R;beginResult.R_Val:= v;end; class operator T_R.add(const v1,v2:T_R):T_R;beginResult.R_Val:= (v1.R_Val + v2.R_Val);end; beginv1:= 1;v2:= 2;v3:= (v1 + v2);writeln('v3 = ',v3.R_Val);end.My main question is: should it be possible to get this program working in {MODE OBJFPC} with {$MODESWITCH ADVANCEDRECORDS} ? And if it is possible, how? Thanks. PS:- I have got other questions, but I will ask them one-at-a-time. ---------------------------------------------------------------------- Warfley · 2024-02-09 18:55 I think that operators are named differently in Mode Delphi and in Mode ObjFPC. In Delphi its names (Explicit, Implicit, Add, Subtract, etc.) and in Mode ObjFpc sind es Symbole (:=, +, -). So either do this in Mode Delphi: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         class operator Implicit(const v:int64):T_R;        class operator add(const v1,v2:T_R):T_R;Or this in mode ObjFPC: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         class operator :=(const v:int64):T_R;        class operator +(const v1,v2:T_R):T_R; But don't mix ---------------------------------------------------------------------- Thaddy · 2024-02-09 19:31 Is correct. ---------------------------------------------------------------------- ad1mt · 2024-02-10 10:35 Quote from: Warfley on February 09, 2024, 07:55:07 pmI think that operators are named differently in Mode Delphi and in Mode ObjFPC. In Delphi its names (Explicit, Implicit, Add, Subtract, etc.) and in Mode ObjFpc sind es Symbole (:=, +, -). But don't mix I've got it working now. Thanks. ---------------------------------------------------------------------- Thaddy · 2024-02-10 11:02 We had about the same question late last year... ---------------------------------------------------------------------- ad1mt · 2024-02-10 11:42 Quote from: Thaddy on February 10, 2024, 12:02:37 pmWe had about the same question late last year... That was probably me. Sorry... I got confused. I'm getting old now, and my brain does not work as well as it used to when I was younger. I now do programming as a hobby, because I'm hoping it will help keep my brain healthy as I get older...