Skip to content

Commit e31ae1a

Browse files
author
miket
committed
added ifdef for generics support, the library is once again compatible with Delphi versions 6 and up.
1 parent a2d88b8 commit e31ae1a

4 files changed

Lines changed: 73 additions & 27 deletions

File tree

src/TZDBPK/TZDB.pas

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ implementation
283283
{$IFNDEF SUPPORTS_MONITOR}
284284
SyncObjs,
285285
{$ENDIF}
286-
{$IFDEF FPC}
287-
Contnrs,
288-
{$ELSE}
286+
{$IFDEF SUPPORTS_GENERICS}
289287
Generics.Collections,
288+
{$ELSE}
289+
Contnrs,
290290
{$ENDIF}
291291
IniFiles;
292292

@@ -540,10 +540,10 @@ TCompiledPeriod = class
540540
FRulesByYearLock: TCriticalSection;
541541
{$ENDIF}
542542
{ Year -> List of Rules for that year }
543-
{$IFDEF FPC}
544-
FRulesByYear: TBucketList; { Word, TList<TCompiledRule> }
545-
{$ELSE}
543+
{$IFDEF SUPPORTS_GENERICS}
546544
FRulesByYear: TDictionary<Word,TList>; { Word, TList<TCompiledRule> }
545+
{$ELSE}
546+
FRulesByYear: TBucketList; { Word, TList<TCompiledRule> }
547547
{$ENDIF}
548548

549549
{ Obtain the last rule that is active in a given year }
@@ -584,9 +584,15 @@ procedure ForEachYearlyRule(AInfo, AItem, AData: Pointer; out AContinue: Boolean
584584
var i: Integer;
585585
begin
586586
{ Free the value list }
587-
for i := 0 to TList(AData).Count - 1 do
588-
TObject(TList(AData).Items[i]).Free;
589-
TList(AData).Free;
587+
if AData <> nil then
588+
begin
589+
if (TList(AData).Count > 0) then
590+
begin
591+
for i := 0 to TList(AData).Count - 1 do
592+
TObject(TList(AData).Items[i]).Free;
593+
end;
594+
TList(AData).Free;
595+
end;
590596
AContinue := True;
591597
end;
592598

@@ -664,10 +670,10 @@ function TCompiledPeriod.CompileRulesForYear(const AYear: Word): TList;
664670

665671
{ Register the new list into the dictionary }
666672
{$WARNINGS OFF}
667-
{$IFDEF FPC}
668-
FRulesByYear.Add(Pointer(AYear), Result);
669-
{$ELSE}
673+
{$IFDEF SUPPORTS_GENERICS}
670674
FRulesByYear.Add(AYear, Result);
675+
{$ELSE}
676+
FRulesByYear.Add(Pointer(AYear), Result);
671677
{$ENDIF}
672678
{$WARNINGS ON}
673679
end;
@@ -681,10 +687,10 @@ constructor TCompiledPeriod.Create(const APeriod: PPeriod; const AFrom, AUntil:
681687
{$IFNDEF SUPPORTS_MONITOR}
682688
FRulesByYearLock := TCriticalSection.Create;
683689
{$ENDIF}
684-
{$IFDEF FPC}
685-
FRulesByYear := TBucketList.Create();
686-
{$ELSE}
690+
{$IFDEF SUPPORTS_GENERICS}
687691
FRulesByYear := TDictionary<Word,TList>.Create;
692+
{$ELSE}
693+
FRulesByYear := TBucketList.Create();
688694
{$ENDIF}
689695
end;
690696

@@ -702,8 +708,13 @@ destructor TCompiledPeriod.Destroy;
702708
{$IFDEF FPC}
703709
FRulesByYear.ForEach(@ForEachYearlyRule);
704710
{$ELSE}
711+
{$IFDEF SUPPORTS_GENERICS}
705712
for L in FRulesByYear.Values do
706713
ForEachYearlyRule(nil, nil, L, c);
714+
{$ELSE}
715+
FRulesByYear.ForEach(ForEachYearlyRule);
716+
{$ENDIF}
717+
707718
{$ENDIF}
708719

709720
FRulesByYear.Free;
@@ -730,10 +741,10 @@ function TCompiledPeriod.FindMatchingRule(const ADateTime: TDateTime): TCompiled
730741
try
731742
{$WARNINGS OFF}
732743
{ Check if we have a cached list of matching rules for this date's year }
733-
{$IFDEF FPC}
734-
if not FRulesByYear.Find(Pointer(LYear), Pointer(LCompiledList)) then
735-
{$ELSE}
744+
{$IFDEF SUPPORTS_GENERICS}
736745
if not FRulesByYear.TryGetValue(LYear, LCompiledList) then
746+
{$ELSE}
747+
if not FRulesByYear.Find(Pointer(LYear), Pointer(LCompiledList)) then
737748
{$ENDIF}
738749
LCompiledList := CompileRulesForYear(LYear);
739750
{$WARNINGS ON}
@@ -1099,9 +1110,17 @@ function TBundledTimeZone.ToISO8601Str(const ADateTime: TDateTime): String;
10991110
destructor TBundledTimeZone.Destroy;
11001111
var i: Integer;
11011112
begin
1102-
for i := 0 to FPeriods.Count - 1 do
1103-
TObject(FPeriods[i]).Free;
1104-
FPeriods.Free;
1113+
if Assigned(FPeriods) then
1114+
begin
1115+
1116+
if (FPeriods.Count > 0) then
1117+
begin
1118+
for i := 0 to FPeriods.Count - 1 do
1119+
TObject(FPeriods[i]).Free;
1120+
end;
1121+
1122+
FPeriods.Free;
1123+
end;
11051124
inherited;
11061125
end;
11071126

src/TZDBPK/Version.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@
1010
{$IFDEF CONDITIONALEXPRESSIONS}
1111

1212
{$IF DECLARED(CompilerVersion)}
13-
{$IF CompilerVersion >= 14}
13+
{$IF CompilerVersion >= 14} //Delphi 6
1414
{$UNDEF UNSUPPORTED_VERSION}
1515
{$IFEND}
16-
{$IF CompilerVersion >= 17}
16+
{$IF CompilerVersion >= 17} //Delphi 2005
1717
{$DEFINE SUPPORTS_INLINE}
1818
{$IFEND}
1919
{$IFEND}
2020

2121
{$IF DECLARED(RTLVersion)}
22-
{$IF RTLVersion >= 20}
22+
{$IF RTLVersion >= 20} //Delphi 2009
2323
{$DEFINE SUPPORTS_MONITOR}
2424
{$DEFINE SUPPORTS_TSTRINGS_OWNSOBJECTS}
25+
{$DEFINE SUPPORTS_GENERICS}
2526
{$IFEND}
26-
{$IF RTLVersion >= 21}
27+
{$IF RTLVersion >= 21} //Delphi 2010
2728
{$DEFINE SUPPORTS_TARRAY}
2829
{$DEFINE SUPPORTS_TTIMESPAN}
2930
{$IFEND}
30-
{$IF RTLVersion >= 22}
31+
{$IF RTLVersion >= 22} //Delphi XE
3132
{$DEFINE SUPPORTS_TTIMEZONE}
3233
{$IFEND}
3334
{$IFEND}

src/TZTest/TestTZDB.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface
3333
TestFramework,
3434
{$IFNDEF SUPPORTS_TARRAY}Types,{$ENDIF}
3535
{$IFDEF SUPPORTS_TTIMESPAN}TimeSpan,{$ENDIF}
36-
Generics.Collections,
36+
Generics.Collections,
3737
Classes,
3838
SysUtils,
3939
TypInfo,

src/TZTest/dunit.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[GUITestRunner Config]
2+
AutoSave=1
3+
Left=642
4+
Top=159
5+
Width=687
6+
Height=697
7+
Maximized=0
8+
UseRegistry=0
9+
ResultsPanel.Height=174
10+
ErrorMessage.Height=75
11+
ErrorMessage.Visible=1
12+
FailureList.ColumnWidth[0]=120
13+
FailureList.ColumnWidth[1]=100
14+
FailureList.ColumnWidth[2]=200
15+
FailureList.ColumnWidth[3]=239
16+
HideTestNodesOnOpen=0
17+
BreakOnFailures=0
18+
FailOnNoChecksExecuted=0
19+
FailOnMemoryLeaked=0
20+
IgnoreSetUpTearDownLeaks=0
21+
ReportMemoryLeakTypes=0
22+
SelectTestedNode=1
23+
WarnOnFailTestOverride=0
24+
PopupX=350
25+
PopupY=30
26+

0 commit comments

Comments
 (0)