--- oup/rewrite/Global/Functions.pas 2007/02/21 00:29:27 105 +++ oup/current/Global/Functions.pas 2009/05/06 13:47:23 321 @@ -5,7 +5,6 @@ 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; @@ -13,6 +12,9 @@ function Encode_Float(input: Single): TB 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; @@ -48,37 +50,6 @@ 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 - Result := StrToInt(hex) - else - Result := 0; -end; - - function Decode_Int(buffer: TByteData): LongWord; begin Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256; @@ -169,6 +140,34 @@ 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; begin @@ -201,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 := ''; @@ -234,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