| 1 | unit City;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Graphics, Generics.Collections, RegistryEx;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | { TCity }
|
|---|
| 11 |
|
|---|
| 12 | TCity = class
|
|---|
| 13 | SysName: string;
|
|---|
| 14 | Name: string;
|
|---|
| 15 | Population: Integer;
|
|---|
| 16 | Locked: Boolean;
|
|---|
| 17 | LineColors: array of TColor;
|
|---|
| 18 | InitialLineCount: Integer;
|
|---|
| 19 | PassengersCountToUnlock: Integer;
|
|---|
| 20 | HighestServedPassengerCount: Integer;
|
|---|
| 21 | HighestServedDaysCount: Integer;
|
|---|
| 22 | procedure LoadFromRegistry(Context: TRegistryContext);
|
|---|
| 23 | procedure SaveToRegistry(Context: TRegistryContext);
|
|---|
| 24 | constructor Create;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 | { TCities }
|
|---|
| 28 |
|
|---|
| 29 | TCities = class(TObjectList<TCity>)
|
|---|
| 30 | function SearchBySysName(SysName: string): TCity;
|
|---|
| 31 | function AddNew(SysName, Name: string; Population: Integer): TCity;
|
|---|
| 32 | procedure LoadFromRegistry(Context: TRegistryContext);
|
|---|
| 33 | procedure SaveToRegistry(Context: TRegistryContext);
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | const
|
|---|
| 37 | clDarkYellow = TColor($00dede);
|
|---|
| 38 | clOrange = TColor($0080ff);
|
|---|
| 39 | clBrown = TColor($003090);
|
|---|
| 40 | clCyan = TColor($FFFF00);
|
|---|
| 41 | clPink = TColor($ff69b4);
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | implementation
|
|---|
| 45 |
|
|---|
| 46 | { TCity }
|
|---|
| 47 |
|
|---|
| 48 | procedure TCity.LoadFromRegistry(Context: TRegistryContext);
|
|---|
| 49 | begin
|
|---|
| 50 | with TRegistryEx.Create do
|
|---|
| 51 | try
|
|---|
| 52 | CurrentContext := Context;
|
|---|
| 53 | Locked := ReadBoolWithDefault('Locked', Locked);
|
|---|
| 54 | HighestServedPassengerCount := ReadIntegerWithDefault('HighestServedPassengerCount', HighestServedPassengerCount);
|
|---|
| 55 | HighestServedDaysCount := ReadIntegerWithDefault('HighestServedDaysCount', HighestServedDaysCount);
|
|---|
| 56 | finally
|
|---|
| 57 | Free;
|
|---|
| 58 | end;
|
|---|
| 59 | end;
|
|---|
| 60 |
|
|---|
| 61 | procedure TCity.SaveToRegistry(Context: TRegistryContext);
|
|---|
| 62 | begin
|
|---|
| 63 | with TRegistryEx.Create do
|
|---|
| 64 | try
|
|---|
| 65 | CurrentContext := Context;
|
|---|
| 66 | WriteBool('Locked', Locked);
|
|---|
| 67 | WriteInteger('HighestServedPassengerCount', HighestServedPassengerCount);
|
|---|
| 68 | WriteInteger('HighestServedDaysCount', HighestServedDaysCount);
|
|---|
| 69 | finally
|
|---|
| 70 | Free;
|
|---|
| 71 | end;
|
|---|
| 72 | end;
|
|---|
| 73 |
|
|---|
| 74 | constructor TCity.Create;
|
|---|
| 75 | begin
|
|---|
| 76 | PassengersCountToUnlock := 500;
|
|---|
| 77 | InitialLineCount := 1;
|
|---|
| 78 | LineColors := [clBlue, clRed, clDarkYellow, clGreen,
|
|---|
| 79 | clPurple, clGray, clOrange, clBrown, clCyan];
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | { TCities }
|
|---|
| 83 |
|
|---|
| 84 | function TCities.SearchBySysName(SysName: string): TCity;
|
|---|
| 85 | var
|
|---|
| 86 | I: Integer;
|
|---|
| 87 | begin
|
|---|
| 88 | I := 0;
|
|---|
| 89 | while (I < Count) and (Items[I].SysName <> SysName) do Inc(I);
|
|---|
| 90 | if I < Count then Result := Items[I]
|
|---|
| 91 | else Result := nil;
|
|---|
| 92 | end;
|
|---|
| 93 |
|
|---|
| 94 | function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
|
|---|
| 95 | begin
|
|---|
| 96 | Result := TCity.Create;
|
|---|
| 97 | Result.SysName := SysName;
|
|---|
| 98 | Result.Name := Name;
|
|---|
| 99 | Result.Population := Population;
|
|---|
| 100 | Add(Result);
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | procedure TCities.LoadFromRegistry(Context: TRegistryContext);
|
|---|
| 104 | var
|
|---|
| 105 | City: TCity;
|
|---|
| 106 | begin
|
|---|
| 107 | for City in Self do begin
|
|---|
| 108 | City.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
|
|---|
| 109 | end;
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | procedure TCities.SaveToRegistry(Context: TRegistryContext);
|
|---|
| 113 | var
|
|---|
| 114 | City: TCity;
|
|---|
| 115 | begin
|
|---|
| 116 | for City in Self do begin
|
|---|
| 117 | City.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
|
|---|
| 118 | end;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | end.
|
|---|
| 122 |
|
|---|