source: oup/current/FileClasses/_DataTypes.pas@ 203

Last change on this file since 203 was 126, checked in by alloc, 18 years ago
File size: 2.9 KB
Line 
1unit _DataTypes;
2
3interface
4
5type
6 TDataField = class
7 private
8 FOffset: Integer;
9 FName: String;
10 FDescription: String;
11 FDataLength: Integer;
12 function GetValueAsString: String; virtual; abstract;
13 public
14 constructor Create(Offset: Integer; Name, Description: String);
15
16 property Offset: Integer read FOffset;
17 property Name: String read FName;
18 property Description: String read FDescription;
19 property DataLength: Integer read FDataLength;
20 property ValueAsString: String read GetValueAsString;
21 end;
22
23 TDataFields = array of TDataField;
24
25
26 TInt32 = class(TDataField)
27 private
28 FInt: LongWord;
29 function GetValueAsString: String; override;
30 public
31 constructor Create(Offset: Integer; Name, Description: String);
32 end;
33
34
35 TString = class(TDataField)
36 private
37 FString: String;
38 function GetValueAsString: String; override;
39 public
40 constructor Create(Offset: Integer; Name, Description: String; Length: Integer);
41 end;
42
43
44
45 TArray = class(TDataField)
46 private
47 FDataFields: TDataFields;
48 function GetFieldByOffset(Offset: Integer): TDataField;
49 function GetFieldByIndex(ID: Integer): TDataField;
50 public
51 constructor Create(Offset: Integer; Name, Description: String; Length, Count: Integer);
52 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
53 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
54 end;
55
56implementation
57
58uses
59 SysUtils;
60
61
62{ TDataType }
63
64constructor TDataField.Create(Offset: Integer; Name, Description: String);
65begin
66 FOffset := Offset;
67 FName := Name;
68 FDescription := Description;
69end;
70
71
72
73{ TInt32 }
74
75constructor TInt32.Create(Offset: Integer; Name, Description: String);
76begin
77 inherited Create(Offset, Name, Description);
78end;
79
80function TInt32.GetValueAsString: String;
81begin
82 Result := IntToStr(FInt);
83end;
84
85
86
87{ TString }
88
89constructor TString.Create(Offset: Integer; Name, Description: String;
90 Length: Integer);
91begin
92 inherited Create(Offset, Name, Description);
93
94end;
95
96function TString.GetValueAsString: String;
97begin
98 Result := FString;
99end;
100
101
102
103{ TArray }
104
105constructor TArray.Create(Offset: Integer; Name, Description: String;
106 Length, Count: Integer);
107begin
108 Exit;
109end;
110
111function TArray.GetFieldByIndex(ID: Integer): TDataField;
112begin
113 if ID < Length(FDataFields) then
114 Result := FDataFields[ID]
115 else
116 Result := nil;
117end;
118
119function TArray.GetFieldByOffset(Offset: Integer): TDataField;
120var
121 i: Integer;
122begin
123 Result := nil;
124
125 if Length(FDataFields) > 0 then
126 begin
127 for i := 0 to High(FDataFields) do
128 if FDataFields[i].Offset = Offset then
129 break;
130 if i < Length(FDataFields) then
131 Result := FDataFields[i];
132 end;
133end;
134
135
136end.
Note: See TracBrowser for help on using the repository browser.