source: tags/1.3.0/UCity.pas

Last change on this file was 110, checked in by chronos, 20 months ago
  • Fixed: Wrong registry path separator.
File size: 2.6 KB
Line 
1unit UCity;
2
3interface
4
5uses
6 Classes, SysUtils, Graphics, Generics.Collections, URegistry;
7
8type
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 AddNew(SysName, Name: string; Population: Integer): TCity;
31 procedure LoadFromRegistry(Context: TRegistryContext);
32 procedure SaveToRegistry(Context: TRegistryContext);
33 end;
34
35const
36 clDarkYellow = TColor($00dede);
37 clOrange = TColor($0080ff);
38 clBrown = TColor($003090);
39 clCyan = TColor($FFFF00);
40 clPink = TColor($ff69b4);
41
42
43implementation
44
45{ TCity }
46
47procedure TCity.LoadFromRegistry(Context: TRegistryContext);
48begin
49 with TRegistryEx.Create do
50 try
51 CurrentContext := Context;
52 Locked := ReadBoolWithDefault('Locked', Locked);
53 HighestServedPassengerCount := ReadIntegerWithDefault('HighestServedPassengerCount', HighestServedPassengerCount);
54 HighestServedDaysCount := ReadIntegerWithDefault('HighestServedDaysCount', HighestServedDaysCount);
55 finally
56 Free;
57 end;
58end;
59
60procedure TCity.SaveToRegistry(Context: TRegistryContext);
61begin
62 with TRegistryEx.Create do
63 try
64 CurrentContext := Context;
65 WriteBool('Locked', Locked);
66 WriteInteger('HighestServedPassengerCount', HighestServedPassengerCount);
67 WriteInteger('HighestServedDaysCount', HighestServedDaysCount);
68 finally
69 Free;
70 end;
71end;
72
73constructor TCity.Create;
74begin
75 PassengersCountToUnlock := 500;
76 InitialLineCount := 1;
77 LineColors := [clBlue, clRed, clDarkYellow, clGreen,
78 clPurple, clGray, clOrange, clBrown, clCyan];
79end;
80
81{ TCities }
82
83function TCities.AddNew(SysName, Name: string; Population: Integer): TCity;
84begin
85 Result := TCity.Create;
86 Result.SysName := SysName;
87 Result.Name := Name;
88 Result.Population := Population;
89 Add(Result);
90end;
91
92procedure TCities.LoadFromRegistry(Context: TRegistryContext);
93var
94 City: TCity;
95begin
96 for City in Self do begin
97 City.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
98 end;
99end;
100
101procedure TCities.SaveToRegistry(Context: TRegistryContext);
102var
103 City: TCity;
104begin
105 for City in Self do begin
106 City.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + City.SysName));
107 end;
108end;
109
110end.
111
Note: See TracBrowser for help on using the repository browser.