--- oup/rewrite/Global/Functions.pas 2007/01/22 23:05:45 97 +++ oup/current/Global/Functions.pas 2009/05/06 13:47:23 321 @@ -5,13 +5,16 @@ interface uses TypeDefs, Classes; function BoolToStr(bool: Boolean): String; -function HexToLong(hex: String): LongWord; function Decode_Int(buffer: TByteData): LongWord; function Encode_Int(input: LongWord): TByteData; function Decode_Float(buffer: TByteData): Single; function Encode_Float(input: Single): TByteData; +function IntToBin(Value: Byte): String; function DataToBin(Data: TByteData): String; function BinToInt(bin: String): Byte; +function MakeDatLink(FileID: Integer): Integer; + +function ReadString(Stream: TStream; Offset: Integer): String; function StringSmaller(string1, string2: String): Boolean; @@ -38,7 +41,6 @@ type - function BoolToStr(bool: Boolean): String; begin if bool then @@ -48,70 +50,12 @@ begin end; - - -function HexToLong(hex: String): LongWord; - - function NormalizeHexString(var hex: String): Boolean; - var - i: Byte; - begin - Result := True; - if hex[1] = '$' then - begin - for i := 1 to Length(hex) - 1 do - hex[i] := hex[i + 1]; - SetLength(hex, Length(hex) - 1); - end; - if (hex[1] = '0') and (UpCase(hex[2]) = 'X') then - begin - for i := 1 to Length(hex) - 2 do - hex[i] := hex[i + 2]; - SetLength(hex, Length(hex) - 2); - end; - if Length(hex) = 0 then - Result := False; - end; - -begin - if NormalizeHexString(hex) then - begin - Result := StrToInt(hex); -{ - hex := UpperCase(hex); - Result := 0; - for i := 1 to Length(hex) do - begin - Result := Result shl 4; - case hex[i] of - '0'..'9': - Result := Result + Ord(hex[i]) - 48; - 'A'..'F': - Result := Result + Ord(hex[i]) - 55; - else - Result := 0; - Exit; - end; - end; -} - end - else - begin - Result := 0; - end; -end; - - - - function Decode_Int(buffer: TByteData): LongWord; begin Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256; end; - - function Encode_Int(input: LongWord): TByteData; begin SetLength(Result, 4); @@ -125,8 +69,6 @@ begin end; - - function Decode_Float(buffer: TByteData): Single; var _valueswitcher: TValueSwitcher; @@ -138,8 +80,6 @@ begin end; - - function Encode_Float(input: Single): TByteData; var _valueswitcher: TValueSwitcher; @@ -149,6 +89,14 @@ begin end; +function IntToBin(Value: Byte): String; +var + i: Byte; +begin + Result := ''; + for i := 7 downto 0 do + Result := Result + IntToStr((Value shr i) and $01); +end; function DataToBin(Data: TByteData): String; @@ -172,8 +120,6 @@ begin end; - - function BinToInt(bin: String): Byte; var Add: Integer; @@ -194,6 +140,33 @@ begin end; +function MakeDatLink(FileID: Integer): Integer; +begin + Result := FileID * 256 + 1; +end; + + + + +function ReadString(Stream: TStream; Offset: Integer): String; +var + c: Char; +begin + if Assigned(Stream) then + begin + if Offset >= 0 then + begin + Result := ''; + Stream.Seek(Offset, soFromBeginning); + repeat + Stream.Read(c, 1); + if Ord(c) > 0 then + Result := Result + c; + until Ord(c) = 0; + end; + end; +end; + function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String; @@ -227,7 +200,7 @@ end; function CreateHexString(Data: TByteData; HexOnly: Boolean): String; var string_build, ascii_version: String; - i: LongWord; + i: Integer; begin string_build := ''; ascii_version := ''; @@ -260,7 +233,7 @@ end; function DecodeHexString(hex: String): TByteData; var - i: LongWord; + i: Integer; begin SetLength(Result, Length(hex) div 2); for i := 0 to Length(Result) do