ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/releases/0.34b/FileClasses/_DataTypes.pas
Revision: 205
Committed: Sun May 27 20:07:55 2007 UTC (18 years, 11 months ago) by alloc
Content type: text/x-pascal
File size: 2938 byte(s)
Log Message:

File Contents

# Content
1 unit _DataTypes;
2
3 interface
4
5 type
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
56 implementation
57
58 uses
59 SysUtils;
60
61
62 { TDataType }
63
64 constructor TDataField.Create(Offset: Integer; Name, Description: String);
65 begin
66 FOffset := Offset;
67 FName := Name;
68 FDescription := Description;
69 end;
70
71
72
73 { TInt32 }
74
75 constructor TInt32.Create(Offset: Integer; Name, Description: String);
76 begin
77 inherited Create(Offset, Name, Description);
78 end;
79
80 function TInt32.GetValueAsString: String;
81 begin
82 Result := IntToStr(FInt);
83 end;
84
85
86
87 { TString }
88
89 constructor TString.Create(Offset: Integer; Name, Description: String;
90 Length: Integer);
91 begin
92 inherited Create(Offset, Name, Description);
93
94 end;
95
96 function TString.GetValueAsString: String;
97 begin
98 Result := FString;
99 end;
100
101
102
103 { TArray }
104
105 constructor TArray.Create(Offset: Integer; Name, Description: String;
106 Length, Count: Integer);
107 begin
108 Exit;
109 end;
110
111 function TArray.GetFieldByIndex(ID: Integer): TDataField;
112 begin
113 if ID < Length(FDataFields) then
114 Result := FDataFields[ID]
115 else
116 Result := nil;
117 end;
118
119 function TArray.GetFieldByOffset(Offset: Integer): TDataField;
120 var
121 i: Integer;
122 begin
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;
133 end;
134
135
136 end.