Delphi compatibility lazarus / 21-General ---------------------------------------------------------------------- Janusz 路 2024-04-15 12:14 Hi, I wrote a program in CodeTyphon (based on Free Pascal). Now I need to use Delphi instruction AtomicIncrement. Is there possiblity to use Free Pascal function named AtomicIncrement. I know there is something like this : { delphi compatibility aliases } function AtomicIncrement (var Target: Int64) : Int64; overload; external name maybe is is dll ? I know that is not fair to ask about it but it impossible for me to change CodeTyphon to Lazarus 馃槬 Janusz ---------------------------------------------------------------------- marcov 路 2024-04-15 12:17 This is not known to us. Codetyphon is very in-transparent, and we don't know if it is possible to upgrade FPC there yourself. You could ask on their forum and/or if they plan to release a version with updated trunk ---------------------------------------------------------------------- Fibonacci 路 2024-04-15 13:25 https://www.freepascal.org/daily/doc/rtl/system/interlockedincrement.h tml ---------------------------------------------------------------------- Janusz 路 2024-04-25 11:33 Hi, Thank you for an answer. I need to simulate function with UInt64 argument, too. I got and information that聽 there is unit (?) in FP written for compatibility with Delphi : Here is example : $IFDEF FPC} { delphi compatibility aliases } function AtomicIncrement (var Target: Int64) : Int64; overload; external name 'FPC_INTERLOCKEDINCREMENT'; function AtomicIncrement (var Target: Int64; Value: Int64) : Int64; overload; external name 'FPC_INTERLOCKEDINCREMENT';聽 Where I can find this ? Maybe it is dll ? Janusz ---------------------------------------------------------------------- cdbc 路 2024-04-25 12:06 Hi "AtomicIncrement()" is a builtin in FPC. I can just type this in a form's eventhandler "Result:= AtomicIncrement(someQWord);" edit: Sorry, my bad, the aliases / overloads are implemented in fpc 3.3.1 and I just checked fpc 3.2.2, where they're not 聽 :'( edit2: just put this: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 { delphi compatibility aliases }function AtomicIncrement (var Target: int64): int64; external name 'FPC_INTERLOCKEDINCREMENT';function AtomicIncrement (var Target: QWord): QWord; external name 'FPC_INTERLOCKEDINCREMENT'; in the top of your unit, then it works in fpc 3.2.2 too These aliases are courtesey of @Thaddy, I directly lifted them from GitLab Regards Benny ---------------------------------------------------------------------- Thaddy 路 2024-04-25 16:52 Although that is possible, these are also already exposed in the system unit as: InterlockedIncrement, InterlockedIncrement64 and InterlockedDecrement, InterlockedDecrement64. See: https://www.freepascal.org/docs- html/rtl/system/interlockedincrement.html and family. But indeed, that also needs an alias to be declared. And the way you do it should work too. ---------------------------------------------------------------------- marcov 路 2024-04-25 18:14 But CodeTyphon afaik uses trunk ---------------------------------------------------------------------- Thaddy 路 2024-04-26 06:05 Indeed these atomic aliases are added in trunk. ---------------------------------------------------------------------- cdbc 路 2024-04-26 06:14 Hi @Thaddy: Yup, in 2021 by you Thaddy聽 If you read the 2 edits in my post above, youl'll see, that I directly lifted them from your discussion with @PascalDragon in GitLab...聽 Regards Benny ---------------------------------------------------------------------- Thaddy 路 2024-04-26 08:20 Forgot.聽 It did not make it to 3.2.2, but maybe it is in 3.2.3 fixes. (After all it is a fix for Delphi compatibility and as patches go, very trivial.) ---------------------------------------------------------------------- paule32 路 2024-04-26 10:21 is in the new version operator overloading supported in Delphi mode ? ---------------------------------------------------------------------- Thaddy 路 2024-04-26 10:50 Yes: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 delphi}{$macro on}{ delphi compatibility aliases }{$if fpc_fullversion < 30301}function AtomicIncrement (var Target: integer): integer;overload; external name 'FPC_INTERLOCKEDINCREMENT';function AtomicIncrement (var Target: int64): int64;overload; external name 'FPC_INTERLOCKEDINCREMENT';function AtomicIncrement (var Target: QWord): QWord;overload; external name 'FPC_INTERLOCKEDINCREMENT';// a lot more{$ifend}var聽i:integer = 0;begin聽 AtomicIncrement(i);聽 writeln(i);end. ---------------------------------------------------------------------- paule32 路 2024-04-26 11:53 sorry for misunderstanding. I mean: operator + (const LValue: Integer; const RValue: Integer): Integer; ---------------------------------------------------------------------- Thaddy 路 2024-04-26 14:52 yes, freestanding operators like that are supported in {$mode Delphi}, but note that Delphi itself does not have that feature. It is FreePascal specific. You put your operators in a separate unit, compile that in {$mode objfpc}. You can then use that unit in a program or other unit in {$mode delphi} However, your example will not work and fail with "impossible overload" because there is already a compiler intrinsic with the same signature. Quick example that will work: 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 unit ops;{$mode objfpc}{$H+}// this unit must be compiled in objfpc modeinterfaceoperator +(const left:string ; const right:integer):string;聽implementationoperator +(const left:string ; 聽const right:integer):string;begin聽 聽writestr(Result, left,right);end;end. You can subsequently use it in delphi mode like so: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 delphi}{$H+}uses ops;var聽 a:string = 'test';聽 b:integer = 0; begin聽 writeln(a+b);// prints 'test0'end. Maybe there is a {$Modeswitch xxx}to add it to {$mode delphi} but I either forgot or there isn't any.. ---------------------------------------------------------------------- PascalDragon 路 2024-05-05 11:10 Quote from: paule32 on April 26, 2024, 01:53:42 pmsorry for misunderstanding. I mean: operator + (const LValue: Integer; const RValue: Integer): Integer; It is not allowed to overload operators that have a built-in implementation. ---------------------------------------------------------------------- paule32 路 2024-05-05 11:54 That was an example as I see this feature in fpcobj, not in delphi mode. ---------------------------------------------------------------------- WooBean 路 2024-05-05 12:37 Quote from: Thaddy on April 26, 2024, 12:50:08 pmCode: 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 delphi}{$macro on}{ delphi compatibility aliases }{$if fpc_fullversion < 30301}...// a lot more{$ifend}... I was surprised that we already have a compiler directive "{$ifend}". It could be a nice feature in the future to allow "guessing" needed directive (parts) by programmers. So, "{$ifend}" should be treated as "{$endif}". Now it is not allowed. ---------------------------------------------------------------------- Thaddy 路 2024-05-05 13:21 It is a bit the other way around. {$ifend} is a legacy notation that closes {$if}. Nowadays you can use {$endif} for both {$ifdef} and {$if}. I still prefer to close {$if} with {$ifend} and close {$ifdef} with {$endif}. But is is not required anymore. Reason is simply Delphi compatibility. But the old way makes more notational sense. ---------------------------------------------------------------------- PascalDragon 路 2024-05-07 19:45 Quote from: paule32 on May 05, 2024, 01:54:20 pmThat was an example as I see this feature in fpcobj, not in delphi mode. It doesn't matter. Built-in operators are not overloadable in any mode. That is not going to change.