tracks/delphi/exercises/allergies/uAllergiesExample.pas in trackler-2.1.0.21 vs tracks/delphi/exercises/allergies/uAllergiesExample.pas in trackler-2.1.0.22

- old
+ new

@@ -13,22 +13,22 @@ TAllergies = class(TInterfacedObject, IAllergies) private fScore: integer; fAvailableAllergies: TDictionary<string, integer>; - fAllergyList: TList<string>; function IsInAllergyScore(allergyvalue: integer): Boolean; function GetAllergyList: TList<string>; public - constructor create(aScore: integer); + constructor Create(aScore: integer); + destructor Destroy; override; function AllergicTo(allergy: string): Boolean; property IList: TList<string> read GetAllergyList; end; implementation -constructor TAllergies.create(aScore: Integer); +constructor TAllergies.Create(aScore: Integer); begin fScore := aScore; fAvailableAllergies := TDictionary<string, integer>.create; with fAvailableAllergies do begin @@ -39,9 +39,16 @@ Add('tomatoes', 16); Add('chocolate', 32); Add('pollen', 64); Add('cats', 128); end; //with +end; + +destructor TAllergies.Destroy; +begin + if assigned(fAvailableAllergies) then + fAvailableAllergies.DisposeOf; + inherited Destroy; end; function TAllergies.IsInAllergyScore(allergyvalue: Integer): Boolean; begin result := (fScore and allergyvalue) = allergyvalue;