1 | unit _DataTypes;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, _TreeElement;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TContainer = class;
|
---|
10 |
|
---|
11 | TDataField = class(TTreeElement)
|
---|
12 | function GetChildCount: Integer; override;
|
---|
13 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
14 | function GetCaption: String; override;
|
---|
15 | protected
|
---|
16 | FOffset: Integer;
|
---|
17 | FName: String;
|
---|
18 | FDescription: String;
|
---|
19 | FDataLength: Integer;
|
---|
20 | FParentFile: TObject;
|
---|
21 | FParentBlock: TContainer;
|
---|
22 | FChanged: Boolean;
|
---|
23 | FExtraArgs: array of TVarRec;
|
---|
24 | function GetValueAsString: String; virtual;
|
---|
25 | public
|
---|
26 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
27 | Name, Description: String; ExtraArgs: array of const); virtual;
|
---|
28 |
|
---|
29 | procedure Update(Offset, Length: Integer); virtual; abstract;
|
---|
30 |
|
---|
31 | property Offset: Integer read FOffset;
|
---|
32 | property Name: String read FName;
|
---|
33 | property Description: String read FDescription;
|
---|
34 | property DataLength: Integer read FDataLength;
|
---|
35 | property ValueAsString: String read GetValueAsString;
|
---|
36 | end;
|
---|
37 |
|
---|
38 | TFieldType = class of TDataField;
|
---|
39 |
|
---|
40 | TContainer = class(TDataField)
|
---|
41 | public
|
---|
42 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
43 | ExtraArgs: array of const): TDataField; virtual; abstract;
|
---|
44 | procedure UpdateSize; virtual; abstract;
|
---|
45 | end;
|
---|
46 |
|
---|
47 | TBlock = class(TContainer)
|
---|
48 | private
|
---|
49 | FDataFields: array of TDataField;
|
---|
50 | function GetChildCount: Integer; override;
|
---|
51 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
52 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
53 | public
|
---|
54 | // ExtraArgs: Pointer auf Integer: BlockLength <- no longer
|
---|
55 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
56 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
57 | procedure Update(Offset, Length: Integer); override;
|
---|
58 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
59 |
|
---|
60 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
61 | ExtraArgs: array of const): TDataField; override;
|
---|
62 | procedure UpdateSize; override;
|
---|
63 | end;
|
---|
64 |
|
---|
65 |
|
---|
66 | TInt = class(TDataField)
|
---|
67 | private
|
---|
68 | FInt: Integer;
|
---|
69 | function GetValueAsString: String; override;
|
---|
70 | public
|
---|
71 | // ExtraArgs: Pointer auf Integer: Bytes of TInt
|
---|
72 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
73 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
74 | procedure Update(Offset, Length: Integer); override;
|
---|
75 | end;
|
---|
76 |
|
---|
77 |
|
---|
78 | TFloat = class(TDataField)
|
---|
79 | private
|
---|
80 | FFloat: Single;
|
---|
81 | function GetValueAsString: String; override;
|
---|
82 | public
|
---|
83 | // ExtraArgs: none
|
---|
84 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
85 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
86 | procedure Update(Offset, Length: Integer); override;
|
---|
87 | end;
|
---|
88 |
|
---|
89 |
|
---|
90 | TBitSet = class(TDataField)
|
---|
91 | private
|
---|
92 | FBits: Byte;
|
---|
93 | FNames: TStringList;
|
---|
94 | function GetValueAsString: String; override;
|
---|
95 | public
|
---|
96 | // ExtraArgs: Pointer auf TStringList
|
---|
97 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
98 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
99 | procedure Update(Offset, Length: Integer); override;
|
---|
100 | end;
|
---|
101 |
|
---|
102 |
|
---|
103 | TLevelID = class(TDataField)
|
---|
104 | private
|
---|
105 | FLevelID: Integer;
|
---|
106 | function GetValueAsString: String; override;
|
---|
107 | public
|
---|
108 | // ExtraArgs: keine
|
---|
109 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
110 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
111 | procedure Update(Offset, Length: Integer); override;
|
---|
112 | end;
|
---|
113 |
|
---|
114 |
|
---|
115 | TFileID = class(TDataField)
|
---|
116 | private
|
---|
117 | FFileID: Integer;
|
---|
118 | function GetValueAsString: String; override;
|
---|
119 | public
|
---|
120 | // ExtraArgs: keine
|
---|
121 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
122 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
123 | procedure Update(Offset, Length: Integer); override;
|
---|
124 | end;
|
---|
125 |
|
---|
126 |
|
---|
127 | TLinkByID = class(TDataField)
|
---|
128 | function GetChildCount: Integer; override;
|
---|
129 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
130 | private
|
---|
131 | FFileID: Integer;
|
---|
132 | FPosExts: String;
|
---|
133 | function GetValueAsString: String; override;
|
---|
134 | public
|
---|
135 | // ExtraArgs: Pointer auf String: Possible Exts
|
---|
136 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
137 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
138 | procedure Update(Offset, Length: Integer); override;
|
---|
139 | end;
|
---|
140 |
|
---|
141 |
|
---|
142 | TString = class(TDataField)
|
---|
143 | private
|
---|
144 | FString: String;
|
---|
145 | function GetValueAsString: String; override;
|
---|
146 | public
|
---|
147 | // ExtraArgs: Pointer auf Integer: Length
|
---|
148 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
149 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
150 | procedure Update(Offset, Length: Integer); override;
|
---|
151 | end;
|
---|
152 |
|
---|
153 |
|
---|
154 | TArray = class(TContainer)
|
---|
155 | private
|
---|
156 | FDataFields: array of TBlock;
|
---|
157 | FTemplate: TBlock;
|
---|
158 | FCounterSize: Integer;
|
---|
159 | FBlockCount: Integer;
|
---|
160 | function GetChildCount: Integer; override;
|
---|
161 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
162 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
163 | public
|
---|
164 | // ExtraArgs:
|
---|
165 | // 1. Integer: CounterSize (if 0 then 2. integer is required)
|
---|
166 | // 2. Integer: BlockCount (for fixed-size arrays)
|
---|
167 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
168 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
169 | procedure Update(Offset, Length: Integer); override;
|
---|
170 |
|
---|
171 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
172 | ExtraArgs: array of const): TDataField; override;
|
---|
173 | procedure SetCount; overload;
|
---|
174 | procedure SetCount(n: Integer); overload;
|
---|
175 | procedure UpdateSize; override;
|
---|
176 | end;
|
---|
177 |
|
---|
178 |
|
---|
179 | TRawLink = class(TDataField)
|
---|
180 | private
|
---|
181 | FRawAddress: Integer;
|
---|
182 | function GetValueAsString: String; override;
|
---|
183 | public
|
---|
184 | // ExtraArgs: keine
|
---|
185 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
186 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
187 | procedure Update(Offset, Length: Integer); override;
|
---|
188 | end;
|
---|
189 |
|
---|
190 |
|
---|
191 | TUnused = class(TDataField)
|
---|
192 | private
|
---|
193 | function GetValueAsString: String; override;
|
---|
194 | public
|
---|
195 | // ExtraArgs: Pointer auf Integer: Length
|
---|
196 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
197 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
198 | procedure Update(Offset, Length: Integer); override;
|
---|
199 | end;
|
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | implementation
|
---|
205 |
|
---|
206 | uses
|
---|
207 | SysUtils, Dialogs, _FileTypes, ConnectionManager, StrUtils;
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 | { TDataType }
|
---|
213 |
|
---|
214 | constructor TDataField.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
215 | Name, Description: String; ExtraArgs: array of const);
|
---|
216 | var
|
---|
217 | i: Integer;
|
---|
218 | begin
|
---|
219 | if Assigned(ParentBlock) then
|
---|
220 | FOffset := ParentBlock.Offset + ParentBlock.DataLength
|
---|
221 | else
|
---|
222 | FOffset := 0;
|
---|
223 | FName := Name;
|
---|
224 | FDescription := Description;
|
---|
225 | FParentFile := ParentFile;
|
---|
226 | FParentBlock := ParentBlock;
|
---|
227 | SetLength(FExtraArgs, Length(ExtraArgs));
|
---|
228 | if Length(ExtraArgs) > 0 then
|
---|
229 | for i := 0 to High(ExtraArgs) do
|
---|
230 | FExtraArgs[i] := ExtraArgs[i];
|
---|
231 | FConnectionID := TFile(ParentFile).ConnectionID;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | function TDataField.GetCaption: String;
|
---|
235 | begin
|
---|
236 | Result := FName;
|
---|
237 | end;
|
---|
238 |
|
---|
239 | function TDataField.GetChild(ID: Integer): TTreeElement;
|
---|
240 | begin
|
---|
241 | Result := nil;
|
---|
242 | end;
|
---|
243 |
|
---|
244 | function TDataField.GetChildCount: Integer;
|
---|
245 | begin
|
---|
246 | Result := 0;
|
---|
247 | end;
|
---|
248 |
|
---|
249 | function TDataField.GetValueAsString: String;
|
---|
250 | begin
|
---|
251 | Result := '';
|
---|
252 | end;
|
---|
253 |
|
---|
254 | { TString }
|
---|
255 |
|
---|
256 | constructor TString.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
257 | Name, Description: String; ExtraArgs: array of const);
|
---|
258 | begin
|
---|
259 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
260 | FDataLength := ExtraArgs[0].VInteger;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | function TString.GetValueAsString: String;
|
---|
264 | begin
|
---|
265 | Result := FString;
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TString.Update(Offset, Length: Integer);
|
---|
269 | var
|
---|
270 | fstream: TMemoryStream;
|
---|
271 | i: Integer;
|
---|
272 | begin
|
---|
273 | fstream := TFile(FParentFile).FileStream;
|
---|
274 | fstream.Seek(FOffset, soFromBeginning);
|
---|
275 | SetLength(FString, FDataLength);
|
---|
276 | fstream.Read(FString[1], FDataLength);
|
---|
277 | for i := 1 to FDataLength do
|
---|
278 | if FString[i] = Chr(0) then
|
---|
279 | begin
|
---|
280 | SetLength(FString, i - 1);
|
---|
281 | Break;
|
---|
282 | end;
|
---|
283 | end;
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 | { TInt }
|
---|
288 |
|
---|
289 | constructor TInt.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
290 | Name, Description: String; ExtraArgs: array of const);
|
---|
291 | begin
|
---|
292 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
293 | FDataLength := ExtraArgs[0].VInteger;
|
---|
294 | FInt := 0;
|
---|
295 | end;
|
---|
296 |
|
---|
297 | function TInt.GetValueAsString: String;
|
---|
298 | begin
|
---|
299 | Result := IntToStr(FInt);
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure TInt.Update(Offset, Length: Integer);
|
---|
303 | var
|
---|
304 | fstream: TMemoryStream;
|
---|
305 | begin
|
---|
306 | fstream := TFile(FParentFile).FileStream;
|
---|
307 | fstream.Seek(FOffset, soFromBeginning);
|
---|
308 | fstream.Read(FInt, FDataLength);
|
---|
309 | end;
|
---|
310 |
|
---|
311 |
|
---|
312 |
|
---|
313 | { TArray }
|
---|
314 |
|
---|
315 | function TArray.AddField(fieldtype: TFieldType;
|
---|
316 | Name, Description: String; ExtraArgs: array of const): TDataField;
|
---|
317 | var
|
---|
318 | i: Integer;
|
---|
319 | begin
|
---|
320 | Result := FTemplate.AddField(fieldtype, Name, Description, ExtraArgs);
|
---|
321 | end;
|
---|
322 |
|
---|
323 | constructor TArray.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
324 | Name, Description: String; ExtraArgs: array of const);
|
---|
325 | begin
|
---|
326 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
327 | FCounterSize := ExtraArgs[0].VInteger;
|
---|
328 | if Length(ExtraArgs) = 2 then
|
---|
329 | FBlockCount := ExtraArgs[1].VInteger
|
---|
330 | else
|
---|
331 | FBlockCount := 0;
|
---|
332 | FTemplate := TBlock.Create(ParentFile, Self, '', '', []);
|
---|
333 | end;
|
---|
334 |
|
---|
335 | function TArray.GetChildCount: Integer;
|
---|
336 | begin
|
---|
337 | Result := Length(FDataFields);
|
---|
338 | end;
|
---|
339 |
|
---|
340 | function TArray.GetChild(ID: Integer): TTreeElement;
|
---|
341 | begin
|
---|
342 | Result := FDataFields[ID];
|
---|
343 | end;
|
---|
344 |
|
---|
345 | function TArray.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
346 | begin
|
---|
347 | Exit;
|
---|
348 | end;
|
---|
349 |
|
---|
350 | procedure TArray.SetCount;
|
---|
351 | var
|
---|
352 | fstream: TMemoryStream;
|
---|
353 | arr_index: Integer;
|
---|
354 | i: Integer;
|
---|
355 |
|
---|
356 | procedure Add(DestBlock, SrcBlock: TBlock);
|
---|
357 | var
|
---|
358 | fid: Integer;
|
---|
359 | field: TDataField;
|
---|
360 | result: TDataField;
|
---|
361 | begin
|
---|
362 | if Length(SrcBlock.FDataFields) > 0 then
|
---|
363 | begin
|
---|
364 | for fid := 0 to High(SrcBlock.FDataFields) do
|
---|
365 | begin
|
---|
366 | field := SrcBlock.FDataFields[fid];
|
---|
367 | result := DestBlock.AddField(TFieldType(field.ClassType), field.Name, field.Description, field.FExtraArgs);
|
---|
368 | if result is TBlock then
|
---|
369 | Add(TBlock(result), TBlock(field));
|
---|
370 | end;
|
---|
371 | end;
|
---|
372 | end;
|
---|
373 |
|
---|
374 | begin
|
---|
375 | if FCounterSize > 0 then
|
---|
376 | begin
|
---|
377 | fstream := TFile(FParentFile).FileStream;
|
---|
378 | fstream.Seek(Offset, soFromBeginning);
|
---|
379 | FBlockCount := 0;
|
---|
380 | fstream.Read(FBlockCount, FCounterSize);
|
---|
381 | end;
|
---|
382 | FDataLength := FCounterSize;
|
---|
383 | if FBlockCount > 0 then
|
---|
384 | begin
|
---|
385 | for arr_index := 0 to FBlockCount - 1 do
|
---|
386 | begin
|
---|
387 | SetLength(FDataFields, arr_index + 1);
|
---|
388 | FDataFields[arr_index] := TBlock.Create(FParentFile, Self,
|
---|
389 | '[' + IntToStr(arr_index) + ']', '', []);
|
---|
390 | Add(FDataFields[arr_index], FTemplate);
|
---|
391 | end;
|
---|
392 | end;
|
---|
393 | if Pos('[', FName) > 0 then
|
---|
394 | begin
|
---|
395 | if Pos(']', FName) = Length(FName) then
|
---|
396 | begin
|
---|
397 | i := Pos('[', ReverseString(FName));
|
---|
398 | FName := MidStr(FName, 1, Length(FName) - i);
|
---|
399 | end;
|
---|
400 | end;
|
---|
401 | FName := FName + '[' + IntToStr(FBlockCount) + ']';
|
---|
402 | FParentBlock.UpdateSize;
|
---|
403 | end;
|
---|
404 |
|
---|
405 | procedure TArray.SetCount(n: Integer);
|
---|
406 | var
|
---|
407 | fstream: TMemoryStream;
|
---|
408 | begin
|
---|
409 | FBlockCount := n;
|
---|
410 | if FCounterSize > 0 then
|
---|
411 | begin
|
---|
412 | fstream := TFile(FParentFile).FileStream;
|
---|
413 | fstream.Seek(Offset, soFromBeginning);
|
---|
414 | fstream.Write(FBlockCount, FCounterSize);
|
---|
415 | end;
|
---|
416 | SetCount;
|
---|
417 | end;
|
---|
418 |
|
---|
419 | procedure TArray.Update(Offset, Length: Integer);
|
---|
420 | var
|
---|
421 | i: Integer;
|
---|
422 | field: TDataField;
|
---|
423 | begin
|
---|
424 | if System.Length(FDataFields) > 0 then
|
---|
425 | begin
|
---|
426 | if Length > 0 then
|
---|
427 | begin
|
---|
428 | for i := 0 to High(FDataFields) do
|
---|
429 | begin
|
---|
430 | field := FDataFields[i];
|
---|
431 | if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or
|
---|
432 | ((field.Offset > Offset) and (field.Offset < Offset + Length)) or
|
---|
433 | ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then
|
---|
434 | field.Update(Offset, Length);
|
---|
435 | end;
|
---|
436 | end else begin
|
---|
437 | for i := 0 to High(FDataFields) do
|
---|
438 | begin
|
---|
439 | FDataFields[i].Update(Offset, Length);
|
---|
440 | end;
|
---|
441 | end;
|
---|
442 | end;
|
---|
443 | end;
|
---|
444 |
|
---|
445 | procedure TArray.UpdateSize;
|
---|
446 | var
|
---|
447 | i: Integer;
|
---|
448 | begin
|
---|
449 | FDataLength := FCounterSize;
|
---|
450 | if Length(FDataFields) > 0 then
|
---|
451 | for i := 0 to High(FDataFields) do
|
---|
452 | FDataLength := FDataLength + FDataFields[i].DataLength;
|
---|
453 | FParentBlock.UpdateSize;
|
---|
454 | end;
|
---|
455 |
|
---|
456 |
|
---|
457 |
|
---|
458 | { TBlock }
|
---|
459 |
|
---|
460 | function TBlock.AddField(fieldtype: TFieldType; Name,
|
---|
461 | Description: String; ExtraArgs: array of const): TDataField;
|
---|
462 | begin
|
---|
463 | SetLength(FDataFields, Length(FDataFields) + 1);
|
---|
464 | FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
|
---|
465 | FParentFile, Self, Name, Description, ExtraArgs);
|
---|
466 | Result := FDataFields[High(FDataFields)];
|
---|
467 | FDataLength := FDataLength + Result.DataLength;
|
---|
468 | if Assigned(FParentBlock) then
|
---|
469 | FParentBlock.UpdateSize;
|
---|
470 | end;
|
---|
471 |
|
---|
472 | constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
473 | Name, Description: String; ExtraArgs: array of const);
|
---|
474 | begin
|
---|
475 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
476 | end;
|
---|
477 |
|
---|
478 | function TBlock.GetChild(ID: Integer): TTreeElement;
|
---|
479 | begin
|
---|
480 | Result := FDataFields[ID];
|
---|
481 | end;
|
---|
482 |
|
---|
483 | function TBlock.GetChildCount: Integer;
|
---|
484 | begin
|
---|
485 | Result := Length(FDataFields);
|
---|
486 | end;
|
---|
487 |
|
---|
488 | function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
489 | begin
|
---|
490 | Exit;
|
---|
491 | end;
|
---|
492 |
|
---|
493 | procedure TBlock.Update(Offset, Length: Integer);
|
---|
494 | var
|
---|
495 | i: Integer;
|
---|
496 | field: TDataField;
|
---|
497 | begin
|
---|
498 | if System.Length(FDataFields) > 0 then
|
---|
499 | begin
|
---|
500 | if Length > 0 then
|
---|
501 | begin
|
---|
502 | for i := 0 to High(FDataFields) do
|
---|
503 | begin
|
---|
504 | field := FDataFields[i];
|
---|
505 | if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or
|
---|
506 | ((field.Offset > Offset) and (field.Offset < Offset + Length)) or
|
---|
507 | ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then
|
---|
508 | field.Update(Offset, Length);
|
---|
509 | end;
|
---|
510 | end else begin
|
---|
511 | for i := 0 to High(FDataFields) do
|
---|
512 | begin
|
---|
513 | FDataFields[i].Update(Offset, Length);
|
---|
514 | end;
|
---|
515 | end;
|
---|
516 | end;
|
---|
517 | end;
|
---|
518 |
|
---|
519 | procedure TBlock.UpdateSize;
|
---|
520 | var
|
---|
521 | i: Integer;
|
---|
522 | begin
|
---|
523 | FDataLength := 0;
|
---|
524 | if Length(FDataFields) > 0 then
|
---|
525 | for i := 0 to High(FDataFields) do
|
---|
526 | FDataLength := FDataLength + FDataFields[i].FDataLength;
|
---|
527 | if Assigned(FParentBlock) then
|
---|
528 | FParentBlock.UpdateSize;
|
---|
529 | end;
|
---|
530 |
|
---|
531 |
|
---|
532 |
|
---|
533 | { TLevelID }
|
---|
534 |
|
---|
535 | constructor TLevelID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
536 | Name, Description: String; ExtraArgs: array of const);
|
---|
537 | begin
|
---|
538 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
539 | FDataLength := 4;
|
---|
540 | FLevelID := 0;
|
---|
541 | end;
|
---|
542 |
|
---|
543 | function TLevelID.GetValueAsString: String;
|
---|
544 | begin
|
---|
545 | Result := IntToStr(FLevelID);
|
---|
546 | end;
|
---|
547 |
|
---|
548 | procedure TLevelID.Update(Offset, Length: Integer);
|
---|
549 | var
|
---|
550 | fstream: TMemoryStream;
|
---|
551 | begin
|
---|
552 | fstream := TFile(FParentFile).FileStream;
|
---|
553 | fstream.Seek(FOffset, soFromBeginning);
|
---|
554 | fstream.Read(FLevelID, 4);
|
---|
555 | FLevelID := FLevelID div 256 div 256 div 256 div 2;
|
---|
556 | end;
|
---|
557 |
|
---|
558 |
|
---|
559 |
|
---|
560 | { TFileID }
|
---|
561 |
|
---|
562 | constructor TFileID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
563 | Name, Description: String; ExtraArgs: array of const);
|
---|
564 | begin
|
---|
565 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
566 | FDataLength := 4;
|
---|
567 | FFileID := -1;
|
---|
568 | end;
|
---|
569 |
|
---|
570 | function TFileID.GetValueAsString: String;
|
---|
571 | begin
|
---|
572 | Result := IntToStr(FFileID);
|
---|
573 | end;
|
---|
574 |
|
---|
575 | procedure TFileID.Update(Offset, Length: Integer);
|
---|
576 | var
|
---|
577 | fstream: TMemoryStream;
|
---|
578 | begin
|
---|
579 | fstream := TFile(FParentFile).FileStream;
|
---|
580 | fstream.Seek(FOffset, soFromBeginning);
|
---|
581 | fstream.Read(FFileID, 4);
|
---|
582 | if FFileID > 0 then
|
---|
583 | FFileID := FFileID div 256
|
---|
584 | else
|
---|
585 | FFileID := -1;
|
---|
586 | end;
|
---|
587 |
|
---|
588 |
|
---|
589 |
|
---|
590 | { TLinkByID }
|
---|
591 |
|
---|
592 | constructor TLinkByID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
593 | Name, Description: String; ExtraArgs: array of const);
|
---|
594 | begin
|
---|
595 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
596 | FDataLength := 4;
|
---|
597 | case ExtraArgs[0].VType of
|
---|
598 | vtChar: FPosExts := ExtraArgs[0].VChar;
|
---|
599 | vtAnsiString: FPosExts := String(ExtraArgs[0].VAnsiString);
|
---|
600 | end;
|
---|
601 | FFileID := -1;
|
---|
602 | end;
|
---|
603 |
|
---|
604 | function TLinkByID.GetChild(ID: Integer): TTreeElement;
|
---|
605 | begin
|
---|
606 | if FFileID > 0 then
|
---|
607 | Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID].Child[ID]
|
---|
608 | else
|
---|
609 | Result := nil;
|
---|
610 | end;
|
---|
611 |
|
---|
612 | function TLinkByID.GetChildCount: Integer;
|
---|
613 | begin
|
---|
614 | if FFileID > 0 then
|
---|
615 | Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID].ChildCount
|
---|
616 | else
|
---|
617 | Result := 0;
|
---|
618 | end;
|
---|
619 |
|
---|
620 | function TLinkByID.GetValueAsString: String;
|
---|
621 | begin
|
---|
622 | if FFileID >= 0 then
|
---|
623 | Result := IntToStr(FFileID)
|
---|
624 | else
|
---|
625 | Result := 'unused';
|
---|
626 | end;
|
---|
627 |
|
---|
628 | procedure TLinkByID.Update(Offset, Length: Integer);
|
---|
629 | var
|
---|
630 | fstream: TMemoryStream;
|
---|
631 | begin
|
---|
632 | fstream := TFile(FParentFile).FileStream;
|
---|
633 | fstream.Seek(FOffset, soFromBeginning);
|
---|
634 | fstream.Read(FFileID, 4);
|
---|
635 | if FFileID > 0 then
|
---|
636 | FFileID := FFileID div 256
|
---|
637 | else
|
---|
638 | FFileID := -1;
|
---|
639 | end;
|
---|
640 |
|
---|
641 |
|
---|
642 |
|
---|
643 | { TRawLink }
|
---|
644 |
|
---|
645 | constructor TRawLink.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
646 | Name, Description: String; ExtraArgs: array of const);
|
---|
647 | begin
|
---|
648 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
649 | FDataLength := 4;
|
---|
650 | end;
|
---|
651 |
|
---|
652 | function TRawLink.GetValueAsString: String;
|
---|
653 | begin
|
---|
654 | if FRawAddress > 0 then
|
---|
655 | Result := '0x' + IntToHex(FRawAddress, 8)
|
---|
656 | else
|
---|
657 | Result := 'unused';
|
---|
658 | end;
|
---|
659 |
|
---|
660 | procedure TRawLink.Update(Offset, Length: Integer);
|
---|
661 | var
|
---|
662 | fstream: TMemoryStream;
|
---|
663 | begin
|
---|
664 | fstream := TFile(FParentFile).FileStream;
|
---|
665 | fstream.Seek(FOffset, soFromBeginning);
|
---|
666 | fstream.Read(FRawAddress, 4);
|
---|
667 | end;
|
---|
668 |
|
---|
669 |
|
---|
670 |
|
---|
671 | { TUnused }
|
---|
672 |
|
---|
673 | constructor TUnused.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
674 | Name, Description: String; ExtraArgs: array of const);
|
---|
675 | begin
|
---|
676 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
677 | FDataLength := ExtraArgs[0].VInteger;
|
---|
678 | end;
|
---|
679 |
|
---|
680 | function TUnused.GetValueAsString: String;
|
---|
681 | begin
|
---|
682 | Result := '';
|
---|
683 | end;
|
---|
684 |
|
---|
685 | procedure TUnused.Update(Offset, Length: Integer);
|
---|
686 | begin
|
---|
687 | Exit;
|
---|
688 | end;
|
---|
689 |
|
---|
690 |
|
---|
691 |
|
---|
692 | { TBitSet }
|
---|
693 |
|
---|
694 | constructor TBitSet.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
695 | Name, Description: String; ExtraArgs: array of const);
|
---|
696 | var
|
---|
697 | i: Integer;
|
---|
698 | begin
|
---|
699 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
700 | FNames := TStringList.Create;
|
---|
701 | for i := 0 to High(ExtraArgs) do
|
---|
702 | case ExtraArgs[i].VType of
|
---|
703 | vtChar: FNames.Add(ExtraArgs[0].VChar);
|
---|
704 | vtAnsiString: FNames.Add(String(ExtraArgs[0].VAnsiString));
|
---|
705 | end;
|
---|
706 | FDataLength := 1;
|
---|
707 | FBits := 0;
|
---|
708 | end;
|
---|
709 |
|
---|
710 | function TBitSet.GetValueAsString: String;
|
---|
711 | function IntToBits(Int: Integer): String;
|
---|
712 | var
|
---|
713 | i: Integer;
|
---|
714 | begin
|
---|
715 | Result := '';
|
---|
716 | for i := 0 to 7 do
|
---|
717 | begin
|
---|
718 | Result := IntToStr(FBits and (1 shl i) shr i) + Result;
|
---|
719 | end;
|
---|
720 | end;
|
---|
721 | begin
|
---|
722 | Result := IntToBits(FBits);
|
---|
723 | end;
|
---|
724 |
|
---|
725 | procedure TBitSet.Update(Offset, Length: Integer);
|
---|
726 | var
|
---|
727 | fstream: TMemoryStream;
|
---|
728 | begin
|
---|
729 | fstream := TFile(FParentFile).FileStream;
|
---|
730 | fstream.Seek(FOffset, soFromBeginning);
|
---|
731 | fstream.Read(FBits, FDataLength);
|
---|
732 | end;
|
---|
733 |
|
---|
734 |
|
---|
735 |
|
---|
736 | { TFloat }
|
---|
737 |
|
---|
738 | constructor TFloat.Create(ParentFile: TObject; ParentBlock: TContainer; Name,
|
---|
739 | Description: String; ExtraArgs: array of const);
|
---|
740 | begin
|
---|
741 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
742 | FDataLength := 4;
|
---|
743 | FFloat := 0;
|
---|
744 | end;
|
---|
745 |
|
---|
746 | function TFloat.GetValueAsString: String;
|
---|
747 | begin
|
---|
748 | Result := FloatToStr(FFloat);
|
---|
749 | end;
|
---|
750 |
|
---|
751 | procedure TFloat.Update(Offset, Length: Integer);
|
---|
752 | var
|
---|
753 | fstream: TMemoryStream;
|
---|
754 | begin
|
---|
755 | fstream := TFile(FParentFile).FileStream;
|
---|
756 | fstream.Seek(FOffset, soFromBeginning);
|
---|
757 | fstream.Read(FFloat, FDataLength);
|
---|
758 | end;
|
---|
759 |
|
---|
760 |
|
---|
761 | end.
|
---|