Forum > General

System.SysUtils, System.Classes....

(1/3) > >>

Molochnik:
I keep replacing such unit names removing namespace prefix, cause otherwise they cannot be found, but am I right?

KodeZwerg:
When programming parallel (Delphi and Lazarus) on same units, than I prefer conditional compiling so Delphi is happy with its namespace and Lazarus is happy too :D

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IFDEF FPC}uses SysUtils, Classes....{$ELSE FPC}// in here you could also add a second condition for older Delphi versionsuses System.SysUtils, System.Classes....{$ENDIF FPC}

Wallaby:
The name spaced approach will soon work with FPC as well.

Most units have been converted to name-spaced versions, e.g. https://gitlab.com/freepascal.org/fpc/source/-/blob/main/rtl/namespaced/common/System.SysUtils.pp

Molochnik:
KodeZwerg
That's cool! With such approach its easy to make even gcc happy.  :D

KodeZwerg:
I am glad you liking it.
Here is a more comprehensive approach:
(the content of this i put into a file called "kz.inc")

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IF Defined(DCC) or Defined(VER210) or Defined(VER200) or Defined(VER190) or Defined(VER185) or Defined(VER180) or Defined(VER170) or Defined(VER160) or Defined(VER150) or Defined(VER140) or Defined(VER130) or Defined(VER120) or Defined(VER100) or Defined(VER90) or Defined(VER80)}  {$DEFINE Delphi} { Delphi }{$IFEND} {$IF Defined(DELPHI) and Declared(CompilerVersion) and (CompilerVersion >= 25)}  {$LEGACYIFEND ON}{$IFEND} {$IF Defined(FPC)}  {$DEFINE Lazarus} { Lazarus and Free Pascal }{$IFEND} {$IF Defined(DELPHI) and Declared(CompilerVersion) and (CompilerVersion >= 23)}  {$DEFINE NameSpace} { Delphis NameSpace feature (eg Winapi.Windows instead of Windows) }{$IFEND} {$IF Defined(DELPHI) and Declared(CompilerVersion) and (CompilerVersion >= 20)}  {$DEFINE UniCode} { Delphis UniCode support }{$IFEND} {$IF Defined(WIN32) or Defined(WIN64) or Defined(MSWindows)}  {$DEFINE Windows} { We are on Windows }{$IFEND Windows} {$IF Defined(FPC) and Declared(FPC_VERSION) and (FPC_VERSION >= 3)}  {$DEFINE UniCode} { FreePascal UniCode support }{$IFEND}and here is an example how to use it:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$I '.\kz.inc'} {$IFDEF FPC}{$mode objfpc}{$H+}{$ENDIF FPC} interface uses{$IFDEF DELPHI}  {$IFDEF NameSpace}    {$IFDEF Windows}      Winapi.Windows,    {$ENDIF Windows}    System.SysUtils, System.Classes,    Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,  {$ELSE NameSpace}    {$IFDEF Windows}      Windows,    {$ENDIF Windows}    SysUtils, Classes,    Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,  {$ENDIF NameSpace}{$ENDIF DELPHI}{$IFDEF FPC}  {$IFDEF Windows}    Windows,  {$ENDIF Windows}  SysUtils, Classes,  Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,{$ENDIF FPC}// here you can add custom units that always named same wayMyUnit; // <- important!and to load the correct form data:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---implementation {$IFDEF DELPHI}{$R *.dfm}{$ENDIF DELPHI}{$IFDEF FPC}{$R *.lfm}{$ENDIF FPC}For the last one (load form) you will need to have same formdata for Delphi and Lazarus.
In many cases it is enough to copy the lfm or dfm to the other extension, load it once into IDE and watch if it throw errors because Delphi and Lazarus got differences in property names.
After fixing errors with any texteditor (remove the errors by hand) you will have a project that works and compiles for both Pascal Interpreters.

Navigation

[0] Message Index

[#] Next page

Go to full version