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

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