Skip to content

Commit

Permalink
[+] Compatibility with Delphi 2009. 2010, XE
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdp committed Apr 12, 2020
1 parent 284376e commit 61b3c04
Show file tree
Hide file tree
Showing 88 changed files with 2,369 additions and 1,369 deletions.
16 changes: 10 additions & 6 deletions Base/JPL.CmdLineParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}

{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}
{$I .\..\jp.inc}
{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF}

{:<@include(..\doc\unit_JP.CmdLineParser.txt)}

Expand Down Expand Up @@ -55,8 +56,9 @@ interface

type


//TArray<T> = array of T; // Delphi 2009
{$IFDEF DELPHI2009_OR_BELOW}
TArray<T> = array of T;
{$ENDIF}

TClpParsingMode = (cpmCustom, cpmDelphi); { TODO: Zablokować cpmCustom dla Linuksa. Na razie działa prawidłowo tylko na Windowsie. }
{ Does the CommandLineToArgvW equivalent for Linux exists? }
Expand Down Expand Up @@ -357,15 +359,17 @@ procedure SplitStrToArray(s: string; var Arr: {$IFDEF FPC}specialize{$ENDIF} TAr
while x > 0 do
begin
SetLength(Arr, Length(Arr) + 1);
Arr[High(Arr)] := Copy(s, 1, x - 1);
// Arr[High(Arr)] := Copy(s, 1, x - 1);
Arr[Length(Arr) - 1] := Copy(s, 1, x - 1);
s := Copy(s, x + Length(EndLineStr), Length(s));
x := Pos(EndLineStr, s);
end;

if s <> '' then
begin
SetLength(Arr, Length(Arr) + 1);
Arr[High(Arr)] := s;
// Arr[High(Arr)] := s;
Arr[Length(Arr) - 1] := s;
end;
end;
{$endregion copied from JPL units}
Expand Down Expand Up @@ -1923,7 +1927,7 @@ function ParamTypeToStr(const ParamType: TClpParamType): string;
cptStopMarker: Result := 'StopParsingSwitch';
cptString: Result := 'String';
else
Result := '?';
Result := '?'{%H-};
end;
end;
{$endregion ParamTypeToStr}
Expand Down
7 changes: 3 additions & 4 deletions Base/JPL.Console.ColorParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@
}

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
//{$MODESWITCH ADVANCEDRECORDS}

{$I .\..\jp.inc}
{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF}

interface

Expand Down
9 changes: 8 additions & 1 deletion Base/JPL.Console.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
}

{$I .\..\jp.inc}

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$MODESWITCH ADVANCEDRECORDS}
Expand Down Expand Up @@ -234,8 +236,10 @@ TConsole = record
class procedure SetOutputCodePage(AValue: UINT); static;
{$ENDIF}

{$IF Defined(FPC) or Defined(DELPHIXE2_OR_ABOVE)}
class function GetTextCodePage: Cardinal; static;
class procedure SetTextCodePage(AValue: Cardinal); static;
{$IFEND}
public

{$region ' colors '}
Expand Down Expand Up @@ -369,7 +373,9 @@ TConsole = record
class property OriginalOutputCodePage: UINT read FOriginalOutputCodePage;
class property OutputCodePage: UINT read GetOutputCodePage write SetOutputCodePage;
{$ENDIF}
{$IF Defined(FPC) or Defined(DELPHIXE2_OR_ABOVE)}
class property TextCodePage: Cardinal read GetTextCodePage write SetTextCodePage;
{$IFEND}
end;


Expand Down Expand Up @@ -1169,6 +1175,7 @@ class function TConsole.RestoreOriginalOutputCodePage: Boolean;
end;
{$ENDIF}

{$IF Defined(FPC) or Defined(DELPHIXE2_OR_ABOVE)}
class procedure TConsole.SetTextCodePage(AValue: Cardinal); {$IFDEF FPC}static;{$ENDIF}
begin
System.SetTextCodePage(Output, AValue);
Expand All @@ -1178,7 +1185,7 @@ class function TConsole.GetTextCodePage: Cardinal;
begin
Result := System.GetTextCodePage(Output);
end;

{$IFEND}

class procedure TConsole.ResetColors;
begin
Expand Down
16 changes: 13 additions & 3 deletions Base/JPL.ConsoleApp.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Last mod: 2018.03.18
}

{$I .\..\jp.inc}

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
Expand All @@ -16,7 +18,7 @@ interface

uses
{$IFDEF MSWINDOWS} Windows, ShellApi, {$ENDIF}
SysUtils,
SysUtils, Types,
JPL.Strings,
JPL.Console,
JPL.SimpleLogger,
Expand Down Expand Up @@ -379,7 +381,11 @@ procedure TJPConsoleApp.DisplayShortUsage;

procedure TJPConsoleApp.DisplayTaggedText(const TaggedText: string);
var
{$IFDEF DELPHI2009_OR_BELOW}
Arr: TStringDynArray;
{$ELSE}
Arr: {$IFDEF DCC}TArray<string>; {$ELSE}TStringArray; {$ENDIF}
{$ENDIF}
i: integer;
s: string;
begin
Expand All @@ -389,7 +395,7 @@ procedure TJPConsoleApp.DisplayTaggedText(const TaggedText: string);
Exit;
end;

SplitStrToArray(TaggedText, Arr);
JPL.Strings.SplitStrToArray(TaggedText, Arr{%H-});
for i := 0 to High(Arr) do
begin
s := Arr[i];
Expand Down Expand Up @@ -435,13 +441,17 @@ procedure TJPConsoleApp.Display(bBanner, bShortUsage, bUsage, bExtraInfo, bExamp

procedure TJPConsoleApp.DisplayColoredText(const s: string; const cc: TConsoleColors);
var
{$IFDEF DELPHI2009_OR_BELOW}
Arr: TStringDynArray;
{$ELSE}
Arr: {$IFDEF FPC}array of string;{$ELSE}TArray<string>;{$ENDIF}
{$ENDIF}
i: integer;
s2: string;
begin
if UseColors then
begin
SplitStrToArray(s, Arr);
JPL.Strings.SplitStrToArray(s, Arr{%H-});
for i := 0 to High(Arr) do
begin
s2 := Arr[i];
Expand Down
23 changes: 12 additions & 11 deletions Base/JPL.Conversion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
}


{$I .\..\jp.inc}

{$IFDEF FPC}
{$I JppFPC.Inc}
{$mode objfpc}{$H+}
{$ENDIF}

Expand Down Expand Up @@ -420,22 +421,22 @@ function IsValidFloat(const s: string): Boolean;

function TryStoF(s: string; var x: Double): Boolean; overload;
begin
s := StringReplace(s, ',', FormatSettings.DecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, '.', FormatSettings.DecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, ',', GetDecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, '.', GetDecimalSeparator{%H-}, [rfReplaceAll]);
Result := TryStrToFloat(s, x);
end;

function TryStoF(s: string; var x: Single): Boolean; overload;
begin
s := StringReplace(s, ',', FormatSettings.DecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, '.', FormatSettings.DecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, ',', GetDecimalSeparator{%H-}, [rfReplaceAll]);
s := StringReplace(s, '.', GetDecimalSeparator{%H-}, [rfReplaceAll]);
Result := TryStrToFloat(s, x);
end;

function stof(s: string; ErrorValue: Real): Real;
begin
s := StringReplace(s, ',', FormatSettings.DecimalSeparator, [rfReplaceAll]);
s := StringReplace(s, '.', FormatSettings.DecimalSeparator, [rfReplaceAll]);
s := StringReplace(s, ',', GetDecimalSeparator, [rfReplaceAll]);
s := StringReplace(s, '.', GetDecimalSeparator, [rfReplaceAll]);
try
Result := StrToFloat(s);
except
Expand Down Expand Up @@ -463,8 +464,8 @@ function ftos(xr: Extended; RoundTo: integer = 2; DSep: string = ''): string;
Delete(s, i, 1);
end;
end;
if s[Length(s)] = FormatSettings.DecimalSeparator then Delete(s, Length(s), 1);
if DSep <> '' then s := StringReplace(s, FormatSettings.DecimalSeparator, DSep, []);
if s[Length(s)] = GetDecimalSeparator then Delete(s, Length(s), 1);
if DSep <> '' then s := StringReplace(s, GetDecimalSeparator, DSep, []);
Result := s;
end;

Expand All @@ -473,7 +474,7 @@ function ftosEx(xr: Extended; Format: string = '0.00'; DecSeparator: string = '.
xp, i, Len, k: integer;
begin
Result := FormatFloat(Format, xr);
Result := StringReplace(Result, FormatSettings.DecimalSeparator, DecSeparator, []);
Result := StringReplace(Result, GetDecimalSeparator, DecSeparator, []);

xp := Pos(DecSeparator, Result);
if xp = 0 then xp := Length(Result);
Expand Down Expand Up @@ -581,7 +582,7 @@ function TryBinToInt(BinStr: string; var xInt: Int64): Boolean;
x := Pos('1', BinStr);
Deleted := Deleted + x;
SetLength(arr, Length(arr) + 1);
arr[Length(arr) - 1] := LengthBin - Deleted;
arr[Length(arr) - 1] := Int64(LengthBin) - Int64(Deleted);
BinStr := Copy(BinStr, x + 1, Length(BinStr));
until (Pos('1', BinStr) = 0);

Expand Down
21 changes: 11 additions & 10 deletions Base/JPL.DateTime.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
http://www.pazera-software.com
}

{$I .\..\jp.inc}
{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}

interface
Expand Down Expand Up @@ -116,7 +117,7 @@ function MsToSecStr(const Ms: integer; PaddingS: Byte = 4; PaddingMs: Byte = 3):
begin
sec := ms div 1000;
msec := ms mod 1000;
Result := Pad(IntToStr(sec), PaddingS, '0') + '.' + Pad(IntToStr(msec), 3, '0');
Result := Pad(IntToStr(sec), PaddingS, '0') + '.' + Pad(IntToStr(msec), PaddingMs, '0');
end;

function GetDateTimeStr(dt: TDateTime; Format: string = '$Y.$M.$D-$H;$MIN;$S,$MS'): string;
Expand Down Expand Up @@ -328,19 +329,19 @@ function ParseDate(dt: TDateTime; DateFormat: TDateFormat): string;

if DateFormat = dfLongNames then
s :=
FormatSettings.LongDayNames[dnum] + ', ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.LongDayNames[dnum] + ', ' + {$ELSE}LongDayNames[dnum] + ', ' + {$ENDIF}
Pad(IntToStr(Day), 2, '0') + ' ' +
FormatSettings.LongMonthNames[Month] + ' ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.LongMonthNames[Month] + ' ' + {$ELSE}LongMonthNames[Month] + ' ' + {$ENDIF}
IntToStr(Year)
else if DateFormat = dfShortNames then
s :=
FormatSettings.ShortDayNames[dnum] + ', ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.ShortDayNames[dnum] + ', ' + {$ELSE}ShortDayNames[dnum] + ', ' + {$ENDIF}
Pad(IntToStr(Day), 2, '0') + ' ' +
FormatSettings.ShortMonthNames[Month] + ' ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.ShortMonthNames[Month] + ' ' + {$ELSE}ShortMonthNames[Month] + ' ' + {$ENDIF}
IntToStr(Year)
else if DateFormat = dfShortDay then
s :=
FormatSettings.ShortDayNames[dnum] + ', ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.ShortDayNames[dnum] + ', ' + {$ELSE}ShortDayNames[dnum] + ', ' + {$ENDIF}
Pad(IntToStr(Day), 2, '0') + '.' +
Pad(IntToStr(Month), 2, '0') + '.' +
IntToStr(Year)
Expand All @@ -356,7 +357,7 @@ function ParseDate(dt: TDateTime; DateFormat: TDateFormat): string;
Pad(IntToStr(Day), 2, '0')
else
s :=
FormatSettings.LongDayNames[dnum] + ', ' +
{$IFDEF HAS_FORMATSETTINGS}FormatSettings.LongDayNames[dnum] + ', ' + {$ELSE}LongDayNames[dnum] + ', ' + {$ENDIF}
Pad(IntToStr(Day), 2, '0') + '.' +
Pad(IntToStr(Month), 2, '0') + '.' +
IntToStr(Year);
Expand Down Expand Up @@ -415,11 +416,11 @@ function MsToDateTime(Ms: DWORD): TDateTime;
h, m, s, msec {, msecv}: DWORD;
begin
h := ms div MsHour;
ms := ms - h * MsHour;
ms := ms {%H-}- h * MsHour;
m := ms div MsMin;
ms := ms - DWORD(m * MsMin);
ms := ms {%H-}- DWORD(m * MsMin);
s := ms div MsSec;
ms := ms - s * MsSec;
ms := ms {%H-}- s * MsSec;
//msecv := ms;
msec := ms div 100;

Expand Down
10 changes: 7 additions & 3 deletions Base/JPL.Dialogs.pas
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
unit JPL.Dialogs;

{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}
{$I .\..\jp.inc}
{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF}

interface

uses
{$IFDEF MSWINDOWS}Windows,{$ENDIF}
SysUtils, Graphics, {$IFDEF DCC}System.UITypes, {$ENDIF}
SysUtils, Types, Graphics, {$IFDEF DELPHIXE2_OR_ABOVE}System.UITypes,{$ENDIF}
Forms, Dialogs, Controls, StdCtrls;


Expand Down Expand Up @@ -128,7 +128,11 @@ function ShowWinStr(const MemoText: string; Caption: string = ''; Width: integer
var
Form: TForm;
Memo: TMemo;
{$IFDEF DELPHI2009_OR_BELOW}
Arr: TStringDynArray;
{$ELSE}
Arr: {$IFDEF FPC}specialize{$ENDIF} TArray<string>;
{$ENDIF}
s: string;
i: integer;
begin
Expand Down
4 changes: 2 additions & 2 deletions Base/JPL.FileSearch.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
}


//{$WARN SYMBOL_PLATFORM OFF}

{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}
{$I .\..\jp.inc}
{$IFDEF FPC}{$mode objfpc}{$H+}{$ENDIF}

interface

Expand Down
8 changes: 4 additions & 4 deletions Base/JPL.FileSearcher.pas
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ procedure TJPFileSearcher.SetOnFoundFile(AValue: TJPEnumFilesProcObj);
end;


function EnumDirsProc(CurrentDirNo: integer; CurrentDir: string): Boolean;
function EnumDirsProc({%H-}CurrentDirNo: integer; {%H-}CurrentDir: string): Boolean;
begin
Result := True;
end;

function EnumFilesProc(Dirs, CurrentFileNo, CurrentDirNo: integer; CurrentFile: string): Boolean;
function EnumFilesProc({%H-}Dirs, {%H-}CurrentFileNo, {%H-}CurrentDirNo: integer; {%H-}CurrentFile: string): Boolean;
begin
Result := True;
end;
Expand All @@ -292,7 +292,7 @@ procedure TJPFileSearcher.Search;

function CanContinue: Boolean;
begin
Result := not ( (FFileCountLimit > 0) and (xFiles >= FFileCountLimit) );
Result := not ( (FFileCountLimit > 0) and (xFiles {%H-}>= FFileCountLimit) );
end;

begin
Expand Down Expand Up @@ -369,7 +369,7 @@ function TJPFileSearcher.AddInputWithTag(const Dir: string; FileMasks: array of
ii.Directory := Dir;
ii.RecurseDepth := RecurseDepth;
ii.Tag := Tag;
ii.TagStr := '';
ii.TagStr := TagStr;

ii.FilesToSearch := TFSFilesToSerach.Create;
for i := 0 to High(FileMasks) do ii.FilesToSearch.Add(FileMasks[i]);
Expand Down
Loading

0 comments on commit 61b3c04

Please sign in to comment.