source: tags/1.4.0/Nation.pas

Last change on this file was 344, checked in by chronos, 4 weeks ago
  • Modified: Improved implementation of TItemList class to be generic class to avoid explicit typecasting.
File size: 1.2 KB
Line 
1unit Nation;
2
3interface
4
5uses
6 Classes, SysUtils, Graphics, ItemList;
7
8type
9
10 { TNation }
11
12 TNation = class(TItem)
13 Color: TColor;
14 class function GetFields: TItemFields; override;
15 procedure GetValue(Index: Integer; out Value); override;
16 procedure SetValue(Index: Integer; var Value); override;
17 class function GetClassSysName: string; override;
18 class function GetClassName: string; override;
19 end;
20
21 { TNations }
22
23 TNations = class(TItemList<TNation>)
24 end;
25
26resourcestring
27 SNation = 'Nation';
28 SColor = 'Color';
29
30
31implementation
32
33uses
34 Common;
35
36{ TNation }
37
38class function TNation.GetFields: TItemFields;
39begin
40 Result := inherited;
41 Result.AddField(2, 'Color', SColor, dtColor);
42end;
43
44procedure TNation.GetValue(Index: Integer; out Value);
45begin
46 if Index = 1 then string(Value) := Name
47 else if Index = 2 then TColor(Value) := Color
48 else inherited;
49end;
50
51procedure TNation.SetValue(Index: Integer; var Value);
52begin
53 if Index = 1 then Name := string(Value)
54 else if Index = 2 then Color := TColor(Value)
55 else inherited;
56end;
57
58class function TNation.GetClassSysName: string;
59begin
60 Result := 'Nation';
61end;
62
63class function TNation.GetClassName: string;
64begin
65 Result := SNation;
66end;
67
68end.
69
Note: See TracBrowser for help on using the repository browser.