| Line | |
|---|
| 1 | unit _DataTypes;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | type
|
|---|
| 6 | TDataType = class
|
|---|
| 7 | private
|
|---|
| 8 | function GetDataLength: Integer; virtual; abstract;
|
|---|
| 9 | function GetValueAsString: String; virtual; abstract;
|
|---|
| 10 | published
|
|---|
| 11 | property DataLength: Integer read GetDataLength;
|
|---|
| 12 | // property DataLength: Integer;
|
|---|
| 13 | property ValueAsString: String read GetValueAsString;
|
|---|
| 14 | end;
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | TDataField = record
|
|---|
| 18 | Offset: Integer;
|
|---|
| 19 | Data: TDataType;
|
|---|
| 20 | end;
|
|---|
| 21 | TDataFields = array of TDataField;
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | TInt32 = class(TDataType)
|
|---|
| 25 | private
|
|---|
| 26 | FValue: LongWord;
|
|---|
| 27 | function GetDataLength: Integer; override;
|
|---|
| 28 | function GetValueAsString: String; override;
|
|---|
| 29 | end;
|
|---|
| 30 |
|
|---|
| 31 | TString = class(TDataType)
|
|---|
| 32 | private
|
|---|
| 33 | FString: String;
|
|---|
| 34 | function GetDataLength: Integer; override;
|
|---|
| 35 | function GetValueAsString: String; override;
|
|---|
| 36 | end;
|
|---|
| 37 |
|
|---|
| 38 | implementation
|
|---|
| 39 |
|
|---|
| 40 | uses
|
|---|
| 41 | SysUtils;
|
|---|
| 42 |
|
|---|
| 43 | { TInt32 }
|
|---|
| 44 |
|
|---|
| 45 | function TInt32.GetDataLength: Integer;
|
|---|
| 46 | begin
|
|---|
| 47 | Result := 4;
|
|---|
| 48 | end;
|
|---|
| 49 |
|
|---|
| 50 | function TInt32.GetValueAsString: String;
|
|---|
| 51 | begin
|
|---|
| 52 | Result := IntToStr(FValue);
|
|---|
| 53 | end;
|
|---|
| 54 |
|
|---|
| 55 | { TString }
|
|---|
| 56 |
|
|---|
| 57 | function TString.GetDataLength: Integer;
|
|---|
| 58 | begin
|
|---|
| 59 | Result := Length(FString);
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | function TString.GetValueAsString: String;
|
|---|
| 63 | begin
|
|---|
| 64 | Result := FString;
|
|---|
| 65 | end;
|
|---|
| 66 |
|
|---|
| 67 | end.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.