Skip to content

Commit 9b3d742

Browse files
author
Markus Humm
committed
Remaining Low changes for compiling this with Delphi versions older than XE3.
1 parent 1023f31 commit 9b3d742

File tree

10 files changed

+330
-171
lines changed

10 files changed

+330
-171
lines changed

Demos/Hash_FMX/Hash_FMX.dproj

Lines changed: 232 additions & 168 deletions
Large diffs are not rendered by default.

Source/DECHashBase.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,13 @@ function TDECHash.CalcString(const Value: string; Format: TDECFormatClass): stri
728728
Result := '';
729729
if Length(Value) > 0 then
730730
begin
731+
{$IF CompilerVersion >= 17.0}
731732
Size := Length(Value) * SizeOf(Value[low(Value)]);
732733
Data := CalcBuffer(Value[low(Value)], Size);
734+
{$ELSE}
735+
Size := Length(Value) * SizeOf(Value[1]);
736+
Data := CalcBuffer(Value[1], Size);
737+
{$ENDIF}
733738
Result := StringOf(ValidFormat(Format).Encode(Data));
734739
end
735740
else
@@ -745,10 +750,17 @@ function TDECHash.CalcString(const Value: RawByteString; Format: TDECFormatClass
745750
begin
746751
Result := '';
747752
if Length(Value) > 0 then
753+
{$IF CompilerVersion >= 17.0}
748754
result := BytesToRawString(
749755
ValidFormat(Format).Encode(
750756
CalcBuffer(Value[low(Value)],
751757
Length(Value) * SizeOf(Value[low(Value)]))))
758+
{$ELSE}
759+
result := BytesToRawString(
760+
ValidFormat(Format).Encode(
761+
CalcBuffer(Value[1],
762+
Length(Value) * SizeOf(Value[1]))))
763+
{$ENDIF}
752764
else
753765
begin
754766
SetLength(Buf, 0);

Source/DECRandom.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ function RandomBytes(Size: Integer): TBytes;
286286
function RandomRawByteString(Size: Integer): RawByteString;
287287
begin
288288
SetLength(Result, Size);
289+
{$IF CompilerVersion >= 17.0}
289290
RandomBuffer(Result[Low(Result)], Size);
291+
{$ELSE}
292+
RandomBuffer(Result[1], Size);
293+
{$ENDIF}
290294
end;
291295

292296
function RandomLong: UInt32;

Source/DECUtil.pas

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ procedure ProtectStream(Stream: TStream; SizeToProtect: Int64 = 0);
564564
const
565565
BufferSize = 512;
566566
var
567-
Buffer: String;
567+
Buffer: string;
568568
Count, Bytes, Size: Integer;
569569
Position: Integer;
570570
begin
@@ -595,7 +595,11 @@ procedure ProtectStream(Stream: TStream; SizeToProtect: Int64 = 0);
595595
Bytes := Size;
596596
if Bytes > BufferSize then
597597
Bytes := BufferSize;
598+
{$IF CompilerVersion >= 17.0}
598599
Stream.Write(Buffer[Low(Buffer)], Bytes);
600+
{$ELSE}
601+
Stream.Write(Buffer[1], Bytes);
602+
{$ENDIF}
599603
Dec(Size, Bytes);
600604
end;
601605
end;
@@ -615,7 +619,11 @@ procedure ProtectString(var Source: string);
615619
if Length(Source) > 0 then
616620
begin
617621
System.UniqueString(Source);
622+
{$IF CompilerVersion >= 17.0}
618623
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
624+
{$ELSE}
625+
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
626+
{$ENDIF}
619627
Source := '';
620628
end;
621629
end;
@@ -627,7 +635,11 @@ procedure ProtectString(var Source: RawByteString);
627635
// UniqueString(Source); cannot be called with a RawByteString as there is
628636
// no overload for it, so we need to call our own one.
629637
DECUtilRawByteStringHelper.UniqueString(Source);
638+
{$IF CompilerVersion >= 17.0}
630639
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
640+
{$ELSE}
641+
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
642+
{$ENDIF}
631643
Source := '';
632644
end;
633645
end;
@@ -638,7 +650,11 @@ procedure ProtectString(var Source: AnsiString); overload;
638650
if Length(Source) > 0 then
639651
begin
640652
System.UniqueString(Source);
653+
{$IF CompilerVersion >= 17.0}
641654
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
655+
{$ELSE}
656+
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
657+
{$ENDIF}
642658
Source := '';
643659
end;
644660
end;
@@ -648,7 +664,11 @@ procedure ProtectString(var Source: WideString); overload;
648664
if Length(Source) > 0 then
649665
begin
650666
System.UniqueString(Source); // for OS <> Win, WideString is not RefCounted on Win
667+
{$IF CompilerVersion >= 17.0}
651668
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
669+
{$ELSE}
670+
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
671+
{$ENDIF}
652672
Source := '';
653673
end;
654674
end;
@@ -660,7 +680,11 @@ function BytesToRawString(const Source: TBytes): RawByteString;
660680
if Length(Source) > 0 then
661681
begin
662682
// determine lowest string index for handling of ZeroBasedStrings
683+
{$IF CompilerVersion >= 17.0}
663684
Move(Source[0], Result[Low(result)], Length(Source));
685+
{$ELSE}
686+
Move(Source[0], Result[1], Length(Source));
687+
{$ENDIF}
664688
end;
665689
end;
666690

Unit Tests/Tests/TestDECCRC.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,15 @@ procedure TestCRC.TestCRC16Standalone;
579579
begin
580580
if FTestData[i].Input <> '' then
581581
begin
582+
{$IF CompilerVersion >= 17.0}
582583
CRC := CRC16(0,
583584
FTestData[i].Input[low(FTestData[i].Input)],
584585
length(FTestData[i].Input));
586+
{$ELSE}
587+
CRC := CRC16(0,
588+
FTestData[i].Input[1],
589+
length(FTestData[i].Input));
590+
{$ENDIF}
585591

586592
CheckEquals(FTestData[i].CRC, CRC,
587593
'Wrong CRC16Standalone reult for iteration ' + IntToStr(i));
@@ -705,9 +711,15 @@ procedure TestCRC.TestCRC32Standalone;
705711
begin
706712
if FTestData[i].Input <> '' then
707713
begin
714+
{$IF CompilerVersion >= 17.0}
708715
CRC := CRC32(0,
709716
FTestData[i].Input[low(FTestData[i].Input)],
710717
length(FTestData[i].Input));
718+
{$ELSE}
719+
CRC := CRC32(0,
720+
FTestData[i].Input[1],
721+
length(FTestData[i].Input));
722+
{$ENDIF}
711723

712724
CheckEquals(FTestData[i].CRC, CRC,
713725
'Wrong CRC32Standalone reult for iteration ' + IntToStr(i));

Unit Tests/Tests/TestDECCipherFormats.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ function TestTDECCipherFormats.AnsiStringOf(const Bytes: TBytes): AnsiString;
160160
if Assigned(Bytes) then
161161
begin
162162
SetLength(Result, length(Bytes));
163+
{$IF CompilerVersion >= 17.0}
163164
Move(Bytes[0], Result[low(Result)], length(Bytes));
165+
{$ELSE}
166+
Move(Bytes[0], Result[1], length(Bytes));
167+
{$ENDIF}
164168
end
165169
else
166170
Result := '';

Unit Tests/Tests/TestDECCipherModes.pas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,19 @@ procedure TestTDECCipherModes.DoTestEncode(Data: array of TTestEntry; Mode: TCip
319319
for n := Low(Dest) to High(Dest) do
320320
Result := Result + IntToHex(Dest[n], 2);
321321

322+
{$IF CompilerVersion >= 17.0}
322323
for n := Low(Result) to High(Result) do
323324
CheckEquals(char(Data[i].OutputHex[n]), Result[n],
324325
IntToStr(n+1) + '. position is wrong. ' +
325326
IntToStr(i) + '. test series. Expected: ' +
326327
string(Data[i].OutputHex) + ' was: ' + Result);
328+
{$ELSE}
329+
for n := 1 to Length(Result) do
330+
CheckEquals(char(Data[i].OutputHex[n]), Result[n],
331+
IntToStr(n+1) + '. position is wrong. ' +
332+
IntToStr(i) + '. test series. Expected: ' +
333+
string(Data[i].OutputHex) + ' was: ' + Result);
334+
{$ENDIF}
327335
end;
328336

329337
finally

Unit Tests/Tests/TestDECFormat.pas

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ procedure TestTFormat_Base64.TestIsValidTBytes;
987987
CheckEquals(true, TFormat_Base64.IsValid(SrcBuf));
988988

989989
SetLength(SrcBuf, 1);
990-
for i := 0 to 255 do //Low(Data) to High(Data) do
990+
for i := 0 to 255 do
991991
begin
992992
SrcBuf[0] := i;
993993

@@ -1029,7 +1029,7 @@ procedure TestTFormat_Base64.TestIsValidTypeless;
10291029
CheckEquals(true, TFormat_Base64.IsValid(SrcBuf, 0));
10301030

10311031
SetLength(SrcBuf, 1);
1032-
for i := 0 to 255 do //Low(Data) to High(Data) do
1032+
for i := 0 to 255 do
10331033
begin
10341034
SrcBuf[0] := i;
10351035

@@ -1742,8 +1742,13 @@ procedure TestTFormat_ESCAPE.TestIsValidTypeless;
17421742
if i = $5C then
17431743
Continue;
17441744

1745+
{$IF CompilerVersion >= 17.0}
17451746
CheckEquals(true, TFormat_ESCAPE.IsValid(RawByteString(chr(i))[low(RawByteString)], 1),
17461747
'Failure on ' + chr(i) + ' ');
1748+
{$ELSE}
1749+
CheckEquals(true, TFormat_ESCAPE.IsValid(RawByteString(chr(i))[1], 1),
1750+
'Failure on ' + chr(i) + ' ');
1751+
{$ENDIF}
17471752
end;
17481753

17491754
// check hex chars
@@ -1821,9 +1826,15 @@ procedure TFormatTestsBase.DoTestEncodeDecodeTypeless(EncodeDecodeProc: TEncodeD
18211826
begin
18221827
if length(TestData[i].Input) > 0 then
18231828
begin
1829+
{$IF CompilerVersion >= 17.0}
18241830
pdata := @TestData[i].Input[low(TestData[i].Input)];
18251831

18261832
len := length(TestData[i].Input) * SizeOf(TestData[i].Input[low(TestData[i].Input)]);
1833+
{$ELSE}
1834+
pdata := @TestData[i].Input[1];
1835+
1836+
len := length(TestData[i].Input) * SizeOf(TestData[i].Input[1]);
1837+
{$ENDIF}
18271838
end
18281839
else
18291840
begin

Unit Tests/Tests/TestDECFormatBase.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ procedure TestTFormat.TestUpCaseBinary;
258258
i : Integer;
259259
b, exp, res : Byte;
260260
begin
261+
{$IF CompilerVersion >= 17.0}
261262
for i := Low(InputChars) to High(InputChars) do
262263
begin
263264
b := ord(InputChars[i]);
@@ -266,6 +267,17 @@ procedure TestTFormat.TestUpCaseBinary;
266267

267268
CheckEquals(exp, res);
268269
end;
270+
271+
{$ELSE}
272+
for i := 1 to Length(InputChars) do
273+
begin
274+
b := ord(InputChars[i]);
275+
exp := ord(OutputChars[i]);
276+
res := TDECFormat.UpCaseBinary(b);
277+
278+
CheckEquals(exp, res);
279+
end;
280+
{$ENDIF}
269281
end;
270282

271283
procedure TestTFormat.TestValidFormat;

Unit Tests/Tests/TestDECUtil.pas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,18 @@ procedure TTestBitTwiddling.SwapBytes;
104104
c: Cardinal;
105105
begin
106106
s := Input;
107+
{$IF CompilerVersion >= 17.0}
107108
DECUtil.SwapBytes(s[Low(s)], Length(s));
109+
{$ELSE}
110+
DECUtil.SwapBytes(s[1], Length(s));
111+
{$ENDIF}
108112
CheckEquals(Output, s);
109113

114+
{$IF CompilerVersion >= 17.0}
110115
DECUtil.SwapBytes(s[Low(s)], Length(s));
116+
{$ELSE}
117+
DECUtil.SwapBytes(s[1], Length(s));
118+
{$ENDIF}
111119
CheckEquals(Input, s);
112120

113121
c := 123456789;

0 commit comments

Comments
 (0)