source: oup/current/FileClasses/_DataTypes.pas

Last change on this file was 248, checked in by alloc, 17 years ago
File size: 24.0 KB
RevLine 
[124]1unit _DataTypes;
2
3interface
4
[207]5uses
[233]6 Classes, _TreeElement;
[207]7
[124]8type
[236]9 TContainer = class;
10
[233]11 TDataField = class(TTreeElement)
[207]12 protected
[126]13 FOffset: Integer;
14 FName: String;
[241]15 FType: String;
[126]16 FDescription: String;
17 FDataLength: Integer;
[206]18 FParentFile: TObject;
[236]19 FParentBlock: TContainer;
[206]20 FChanged: Boolean;
[237]21 FExtraArgs: array of TVarRec;
[241]22 function GetChildCount: Integer; override;
23 function GetChild(ID: Integer): TTreeElement; override;
24 function GetCaption: String; override;
25 function GetType: String; override;
[236]26 function GetValueAsString: String; virtual;
[126]27 public
[236]28 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
29 Name, Description: String; ExtraArgs: array of const); virtual;
[126]30
[206]31 procedure Update(Offset, Length: Integer); virtual; abstract;
[240]32 procedure WriteData(stream: TStream); virtual; abstract;
[206]33
[126]34 property Offset: Integer read FOffset;
35 property Name: String read FName;
36 property Description: String read FDescription;
37 property DataLength: Integer read FDataLength;
[124]38 property ValueAsString: String read GetValueAsString;
39 end;
40
[206]41 TFieldType = class of TDataField;
[124]42
[236]43 TContainer = class(TDataField)
44 public
[237]45 function AddField(fieldtype: TFieldType; Name, Description: String;
46 ExtraArgs: array of const): TDataField; virtual; abstract;
[236]47 procedure UpdateSize; virtual; abstract;
48 end;
[207]49
[236]50 TBlock = class(TContainer)
[241]51 protected
[206]52 FDataFields: array of TDataField;
[233]53 function GetChildCount: Integer; override;
54 function GetChild(ID: Integer): TTreeElement; override;
[206]55 function GetFieldByOffset(Offset: Integer): TDataField;
56 public
[236]57 // ExtraArgs: Pointer auf Integer: BlockLength <- no longer
58 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
59 Name, Description: String; ExtraArgs: array of const); override;
[206]60 procedure Update(Offset, Length: Integer); override;
[240]61 procedure WriteData(stream: TStream); override;
[206]62 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
[124]63
[236]64 function AddField(fieldtype: TFieldType; Name, Description: String;
[237]65 ExtraArgs: array of const): TDataField; override;
[236]66 procedure UpdateSize; override;
[206]67 end;
68
69
70 TInt = class(TDataField)
[241]71 protected
[206]72 FInt: Integer;
[124]73 function GetValueAsString: String; override;
[126]74 public
[206]75 // ExtraArgs: Pointer auf Integer: Bytes of TInt
[236]76 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
77 Name, Description: String; ExtraArgs: array of const); override;
[206]78 procedure Update(Offset, Length: Integer); override;
[240]79 procedure WriteData(stream: TStream); override;
[124]80 end;
81
[126]82
[237]83 TFloat = class(TDataField)
[241]84 protected
[237]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;
[240]92 procedure WriteData(stream: TStream); override;
[237]93 end;
94
95
[207]96 TBitSet = class(TDataField)
[241]97 protected
[207]98 FBits: Byte;
99 FNames: TStringList;
100 function GetValueAsString: String; override;
101 public
102 // ExtraArgs: Pointer auf TStringList
[236]103 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
104 Name, Description: String; ExtraArgs: array of const); override;
[207]105 procedure Update(Offset, Length: Integer); override;
[240]106 procedure WriteData(stream: TStream); override;
[207]107 end;
108
109
[206]110 TLevelID = class(TDataField)
[241]111 protected
[206]112 FLevelID: Integer;
113 function GetValueAsString: String; override;
114 public
115 // ExtraArgs: keine
[236]116 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
117 Name, Description: String; ExtraArgs: array of const); override;
[206]118 procedure Update(Offset, Length: Integer); override;
[240]119 procedure WriteData(stream: TStream); override;
[206]120 end;
121
122
[248]123 TResourceID = class(TDataField)
[241]124 protected
[206]125 FFileID: Integer;
126 function GetValueAsString: String; override;
127 public
128 // ExtraArgs: keine
[236]129 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
130 Name, Description: String; ExtraArgs: array of const); override;
[206]131 procedure Update(Offset, Length: Integer); override;
[240]132 procedure WriteData(stream: TStream); override;
[206]133 end;
134
135
[240]136 TDatLink = class(TDataField)
[241]137 protected
138 FPosExts: String;
[240]139 function GetTarget: TObject; virtual; abstract;
140 public
[241]141 property PosExts: String read FPosExts;
[240]142 property TargetFile: TObject read GetTarget;
143 end;
144
145
146 TLinkByID = class(TDatLink)
[241]147 protected
148 FFileID: Integer;
[233]149 function GetChildCount: Integer; override;
150 function GetChild(ID: Integer): TTreeElement; override;
[206]151 function GetValueAsString: String; override;
[240]152 function GetTarget: TObject; override;
[206]153 public
154 // ExtraArgs: Pointer auf String: Possible Exts
[236]155 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
156 Name, Description: String; ExtraArgs: array of const); override;
[206]157 procedure Update(Offset, Length: Integer); override;
[240]158 procedure WriteData(stream: TStream); override;
[206]159 end;
160
161
[126]162 TString = class(TDataField)
[241]163 protected
[124]164 FString: String;
165 function GetValueAsString: String; override;
[126]166 public
[206]167 // ExtraArgs: Pointer auf Integer: Length
[236]168 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
169 Name, Description: String; ExtraArgs: array of const); override;
[206]170 procedure Update(Offset, Length: Integer); override;
[240]171 procedure WriteData(stream: TStream); override;
[124]172 end;
173
[126]174
[236]175 TArray = class(TContainer)
[241]176 protected
[233]177 FDataFields: array of TBlock;
[236]178 FTemplate: TBlock;
179 FCounterSize: Integer;
180 FBlockCount: Integer;
[233]181 function GetChildCount: Integer; override;
182 function GetChild(ID: Integer): TTreeElement; override;
[126]183 function GetFieldByOffset(Offset: Integer): TDataField;
184 public
[237]185 // ExtraArgs:
186 // 1. Integer: CounterSize (if 0 then 2. integer is required)
187 // 2. Integer: BlockCount (for fixed-size arrays)
[236]188 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
189 Name, Description: String; ExtraArgs: array of const); override;
[206]190 procedure Update(Offset, Length: Integer); override;
[240]191 procedure WriteData(stream: TStream); override;
[206]192
[236]193 function AddField(fieldtype: TFieldType; Name, Description: String;
[237]194 ExtraArgs: array of const): TDataField; override;
[236]195 procedure SetCount; overload;
196 procedure SetCount(n: Integer); overload;
197 procedure UpdateSize; override;
[126]198 end;
199
[206]200
201 TRawLink = class(TDataField)
[241]202 protected
[206]203 FRawAddress: Integer;
[241]204 FRawType: String;
205 FSep: Boolean;
[206]206 function GetValueAsString: String; override;
207 public
[241]208 // ExtraArgs: String: RawType; Bool: Sep
[236]209 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
210 Name, Description: String; ExtraArgs: array of const); override;
[206]211 procedure Update(Offset, Length: Integer); override;
[240]212 procedure WriteData(stream: TStream); override;
[241]213
214 property RawType: String read FRawType;
[206]215 end;
216
217
218 TUnused = class(TDataField)
[241]219 protected
[206]220 function GetValueAsString: String; override;
221 public
222 // ExtraArgs: Pointer auf Integer: Length
[236]223 constructor Create(ParentFile: TObject; ParentBlock: TContainer;
224 Name, Description: String; ExtraArgs: array of const); override;
[206]225 procedure Update(Offset, Length: Integer); override;
[240]226 procedure WriteData(stream: TStream); override;
[206]227 end;
228
229
[207]230
231
[124]232implementation
233
234uses
[237]235 SysUtils, Dialogs, _FileTypes, ConnectionManager, StrUtils;
[124]236
[126]237
[207]238
239
[126]240{ TDataType }
241
[236]242constructor TDataField.Create(ParentFile: TObject; ParentBlock: TContainer;
243 Name, Description: String; ExtraArgs: array of const);
[237]244var
245 i: Integer;
[126]246begin
[236]247 if Assigned(ParentBlock) then
248 FOffset := ParentBlock.Offset + ParentBlock.DataLength
249 else
250 FOffset := 0;
[126]251 FName := Name;
[206]252 FDescription := Description;
[212]253 FParentFile := ParentFile;
[236]254 FParentBlock := ParentBlock;
[237]255 SetLength(FExtraArgs, Length(ExtraArgs));
256 if Length(ExtraArgs) > 0 then
257 for i := 0 to High(ExtraArgs) do
258 FExtraArgs[i] := ExtraArgs[i];
[248]259 FConnectionID := TResource(ParentFile).ConnectionID;
[126]260end;
261
[233]262function TDataField.GetCaption: String;
263begin
264 Result := FName;
265end;
[126]266
[233]267function TDataField.GetChild(ID: Integer): TTreeElement;
268begin
269 Result := nil;
270end;
[126]271
[233]272function TDataField.GetChildCount: Integer;
273begin
274 Result := 0;
275end;
276
[241]277function TDataField.GetType: String;
278begin
279 Result := FType;
280end;
281
[236]282function TDataField.GetValueAsString: String;
283begin
284 Result := '';
285end;
[233]286
[207]287{ TString }
[124]288
[236]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;
[241]294 FType := 'String[' + IntToStr(FDataLength) + ']';
[236]295end;
296
297function TString.GetValueAsString: String;
298begin
299 Result := FString;
300end;
301
302procedure TString.Update(Offset, Length: Integer);
[206]303var
304 fstream: TMemoryStream;
[207]305 i: Integer;
[124]306begin
[248]307 fstream := TResource(FParentFile).FileStream;
[236]308 fstream.Seek(FOffset, soFromBeginning);
[207]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;
[124]317end;
318
[240]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;
[124]330
[126]331
[240]332
[207]333{ TInt }
[124]334
[236]335constructor TInt.Create(ParentFile: TObject; ParentBlock: TContainer;
336 Name, Description: String; ExtraArgs: array of const);
[124]337begin
[236]338 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
339 FDataLength := ExtraArgs[0].VInteger;
[241]340 FType := 'Int' + IntToStr(FDataLength * 8);
[207]341 FInt := 0;
[124]342end;
343
[207]344function TInt.GetValueAsString: String;
[124]345begin
[207]346 Result := IntToStr(FInt);
[124]347end;
348
[207]349procedure TInt.Update(Offset, Length: Integer);
[236]350var
351 fstream: TMemoryStream;
[206]352begin
[248]353 fstream := TResource(FParentFile).FileStream;
[236]354 fstream.Seek(FOffset, soFromBeginning);
355 fstream.Read(FInt, FDataLength);
[206]356end;
[126]357
[240]358procedure TInt.WriteData(stream: TStream);
359begin
360 stream.Write(FInt, FDataLength);
361end;
[126]362
[206]363
[240]364
[126]365{ TArray }
366
[236]367function TArray.AddField(fieldtype: TFieldType;
368 Name, Description: String; ExtraArgs: array of const): TDataField;
[234]369var
370 i: Integer;
[126]371begin
[236]372 Result := FTemplate.AddField(fieldtype, Name, Description, ExtraArgs);
[126]373end;
374
[236]375constructor TArray.Create(ParentFile: TObject; ParentBlock: TContainer;
376 Name, Description: String; ExtraArgs: array of const);
[126]377begin
[236]378 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
379 FCounterSize := ExtraArgs[0].VInteger;
[241]380 FType := '';
[237]381 if Length(ExtraArgs) = 2 then
382 FBlockCount := ExtraArgs[1].VInteger
383 else
[236]384 FBlockCount := 0;
385 FTemplate := TBlock.Create(ParentFile, Self, '', '', []);
[126]386end;
387
[233]388function TArray.GetChildCount: Integer;
[206]389begin
390 Result := Length(FDataFields);
391end;
[126]392
[233]393function TArray.GetChild(ID: Integer): TTreeElement;
394begin
395 Result := FDataFields[ID];
396end;
397
398function TArray.GetFieldByOffset(Offset: Integer): TDataField;
399begin
400 Exit;
401end;
402
[236]403procedure TArray.SetCount;
404var
[237]405 fstream: TMemoryStream;
[236]406 arr_index: Integer;
[237]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
[206]427begin
[237]428 if FCounterSize > 0 then
429 begin
[248]430 fstream := TResource(FParentFile).FileStream;
[237]431 fstream.Seek(Offset, soFromBeginning);
432 FBlockCount := 0;
433 fstream.Read(FBlockCount, FCounterSize);
434 end;
[236]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,
[237]442 '[' + IntToStr(arr_index) + ']', '', []);
443 Add(FDataFields[arr_index], FTemplate);
[236]444 end;
445 end;
[237]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;
[236]454 FName := FName + '[' + IntToStr(FBlockCount) + ']';
455 FParentBlock.UpdateSize;
[206]456end;
457
[236]458procedure TArray.SetCount(n: Integer);
[237]459var
460 fstream: TMemoryStream;
[236]461begin
[237]462 FBlockCount := n;
463 if FCounterSize > 0 then
464 begin
[248]465 fstream := TResource(FParentFile).FileStream;
[237]466 fstream.Seek(Offset, soFromBeginning);
467 fstream.Write(FBlockCount, FCounterSize);
468 end;
469 SetCount;
[236]470end;
[206]471
[236]472procedure TArray.Update(Offset, Length: Integer);
[206]473var
474 i: Integer;
[236]475 field: TDataField;
[206]476begin
[236]477 if System.Length(FDataFields) > 0 then
[206]478 begin
[236]479 if Length > 0 then
[206]480 begin
[236]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);
[206]492 end;
493 end;
[236]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
[240]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;
[236]517
518
[240]519
[236]520{ TBlock }
521
522function TBlock.AddField(fieldtype: TFieldType; Name,
523 Description: String; ExtraArgs: array of const): TDataField;
524begin
[206]525 SetLength(FDataFields, Length(FDataFields) + 1);
526 FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
[236]527 FParentFile, Self, Name, Description, ExtraArgs);
[212]528 Result := FDataFields[High(FDataFields)];
[236]529 FDataLength := FDataLength + Result.DataLength;
530 if Assigned(FParentBlock) then
531 FParentBlock.UpdateSize;
[206]532end;
533
[236]534constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
535 Name, Description: String; ExtraArgs: array of const);
[206]536begin
[236]537 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[241]538 FType := '';
[206]539end;
540
[233]541function TBlock.GetChild(ID: Integer): TTreeElement;
[206]542begin
543 Result := FDataFields[ID];
544end;
545
[233]546function TBlock.GetChildCount: Integer;
[206]547begin
[233]548 Result := Length(FDataFields);
[206]549end;
550
[233]551function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
[206]552begin
[233]553 Exit;
[206]554end;
555
556procedure TBlock.Update(Offset, Length: Integer);
[236]557var
558 i: Integer;
559 field: TDataField;
[206]560begin
[236]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;
[206]580end;
581
[236]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;
[206]593
[240]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;
[206]602
[236]603
[206]604{ TLevelID }
605
[236]606constructor TLevelID.Create(ParentFile: TObject; ParentBlock: TContainer;
607 Name, Description: String; ExtraArgs: array of const);
[206]608begin
[236]609 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[206]610 FDataLength := 4;
[241]611 FType := 'LevelID';
[236]612 FLevelID := 0;
[206]613end;
614
615function TLevelID.GetValueAsString: String;
616begin
617 Result := IntToStr(FLevelID);
618end;
619
620procedure TLevelID.Update(Offset, Length: Integer);
[236]621var
622 fstream: TMemoryStream;
[206]623begin
[248]624 fstream := TResource(FParentFile).FileStream;
[236]625 fstream.Seek(FOffset, soFromBeginning);
626 fstream.Read(FLevelID, 4);
627 FLevelID := FLevelID div 256 div 256 div 256 div 2;
[206]628end;
629
[240]630procedure TLevelID.WriteData(stream: TStream);
631var
632 tempi: Integer;
633begin
634 tempi := FLevelID * 256 * 256 * 256 * 2 + 1;
635 stream.Write(tempi, 4);
636end;
[206]637
638
[240]639
[206]640{ TFileID }
641
[248]642constructor TResourceID.Create(ParentFile: TObject; ParentBlock: TContainer;
[236]643 Name, Description: String; ExtraArgs: array of const);
[206]644begin
[236]645 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[206]646 FDataLength := 4;
[241]647 FType := 'FileID';
[236]648 FFileID := -1;
[206]649end;
650
[248]651function TResourceID.GetValueAsString: String;
[206]652begin
653 Result := IntToStr(FFileID);
654end;
655
[248]656procedure TResourceID.Update(Offset, Length: Integer);
[236]657var
658 fstream: TMemoryStream;
[206]659begin
[248]660 fstream := TResource(FParentFile).FileStream;
[236]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;
[206]667end;
668
[248]669procedure TResourceID.WriteData(stream: TStream);
[240]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;
[206]679
680
[240]681
[206]682{ TLinkByID }
683
[236]684constructor TLinkByID.Create(ParentFile: TObject; ParentBlock: TContainer;
685 Name, Description: String; ExtraArgs: array of const);
[206]686begin
[236]687 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[206]688 FDataLength := 4;
[236]689 case ExtraArgs[0].VType of
690 vtChar: FPosExts := ExtraArgs[0].VChar;
691 vtAnsiString: FPosExts := String(ExtraArgs[0].VAnsiString);
692 end;
[241]693 FType := 'LinkByID(' + FPosExts + ')';
[236]694 FFileID := -1;
[206]695end;
696
[233]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
[240]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
[206]721function TLinkByID.GetValueAsString: String;
722begin
[236]723 if FFileID >= 0 then
724 Result := IntToStr(FFileID)
725 else
726 Result := 'unused';
[206]727end;
728
729procedure TLinkByID.Update(Offset, Length: Integer);
[236]730var
731 fstream: TMemoryStream;
[206]732begin
[248]733 fstream := TResource(FParentFile).FileStream;
[236]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;
[206]740end;
741
[240]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;
[206]752
753
[240]754
[206]755{ TRawLink }
756
[236]757constructor TRawLink.Create(ParentFile: TObject; ParentBlock: TContainer;
758 Name, Description: String; ExtraArgs: array of const);
[206]759begin
[236]760 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[241]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 + ')';
[206]768 FDataLength := 4;
769end;
770
771function TRawLink.GetValueAsString: String;
772begin
[236]773 if FRawAddress > 0 then
774 Result := '0x' + IntToHex(FRawAddress, 8)
775 else
776 Result := 'unused';
[206]777end;
778
779procedure TRawLink.Update(Offset, Length: Integer);
[236]780var
781 fstream: TMemoryStream;
[206]782begin
[248]783 fstream := TResource(FParentFile).FileStream;
[236]784 fstream.Seek(FOffset, soFromBeginning);
785 fstream.Read(FRawAddress, 4);
[206]786end;
787
[240]788procedure TRawLink.WriteData(stream: TStream);
789begin
790 stream.Write(FRawAddress, 4);
791end;
[206]792
793
[240]794
[206]795{ TUnused }
796
[236]797constructor TUnused.Create(ParentFile: TObject; ParentBlock: TContainer;
798 Name, Description: String; ExtraArgs: array of const);
[206]799begin
[236]800 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
801 FDataLength := ExtraArgs[0].VInteger;
[241]802 FType := 'Unused';
[206]803end;
804
805function TUnused.GetValueAsString: String;
806begin
807 Result := '';
808end;
809
810procedure TUnused.Update(Offset, Length: Integer);
811begin
812 Exit;
813end;
814
[240]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;
[207]824
825
[240]826
[207]827{ TBitSet }
828
[236]829constructor TBitSet.Create(ParentFile: TObject; ParentBlock: TContainer;
830 Name, Description: String; ExtraArgs: array of const);
[207]831var
[236]832 i: Integer;
[207]833begin
[236]834 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
[207]835 FNames := TStringList.Create;
[236]836 for i := 0 to High(ExtraArgs) do
[243]837 begin
[236]838 case ExtraArgs[i].VType of
[243]839 vtChar: FNames.Add(ExtraArgs[i].VChar);
840 vtAnsiString: FNames.Add(String(ExtraArgs[i].VAnsiString));
[236]841 end;
[243]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;
[207]846 FDataLength := 1;
[241]847 FType := 'BitSet';
[207]848 FBits := 0;
849end;
850
851function TBitSet.GetValueAsString: String;
[236]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;
[207]862begin
[236]863 Result := IntToBits(FBits);
[207]864end;
865
866procedure TBitSet.Update(Offset, Length: Integer);
[236]867var
868 fstream: TMemoryStream;
[207]869begin
[248]870 fstream := TResource(FParentFile).FileStream;
[236]871 fstream.Seek(FOffset, soFromBeginning);
872 fstream.Read(FBits, FDataLength);
[207]873end;
874
[240]875procedure TBitSet.WriteData(stream: TStream);
876begin
877 stream.Write(FBits, FDataLength);
878end;
[237]879
880
[240]881
[237]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;
[241]889 FType := 'Float';
[237]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
[248]902 fstream := TResource(FParentFile).FileStream;
[237]903 fstream.Seek(FOffset, soFromBeginning);
904 fstream.Read(FFloat, FDataLength);
905end;
906
[240]907procedure TFloat.WriteData(stream: TStream);
908begin
909 stream.Write(FFloat, 4);
910end;
[237]911
[240]912
[124]913end.
Note: See TracBrowser for help on using the repository browser.