@@ -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
584584var i: Integer;
585585begin
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;
591597end ;
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}
673679end ;
@@ -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}
689695end ;
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;
10991110destructor TBundledTimeZone.Destroy;
11001111var i: Integer;
11011112begin
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 ;
11061125end ;
11071126
0 commit comments