in der bibliothek JclStrings.pas ist eine funktion: function StrToHex(const Source: string): string;
ich hab das dann eingebundend und
Delphi-Quelltext
1:
| Memo1.text := StrToHex(s); |
geschrieben, was mir eigentlich einen string ausgeben sollte, aber Memo1. bleibt leer.
die ganze funktion sieht so aus:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
| function StrToHex(const Source: string): string; var Index: Integer; C, L, N: Integer; BL, BH: Byte; S: string; {$IFDEF CLR} sb: StringBuilder; {$ENDIF CLR} begin {$IFDEF CLR} sb := StringBuilder.Create; {$ELSE} Result := ''; {$ENDIF CLR} if Source <> '' then begin S := Source; L := Length(S); if Odd(L) then begin S := '0' + S; Inc(L); end; Index := 1; {$IFDEF CLR} sb.Length := L div 2; {$ELSE} SetLength(Result, L div 2); {$ENDIF CLR} C := 1; N := 1; while C <= L do begin BH := CharHex(S[Index]); Inc(Index); BL := CharHex(S[Index]); Inc(Index); Inc(C, 2); if (BH = $FF) or (BL = $FF) then begin Result := ''; Exit; end; {$IFDEF CLR} sb[N] := {$ELSE} Result[N] := {$ENDIF CLR} Char((BH shl 4) + BL); Inc(N); end; end; {$IFDEF CLR} Result := sb.ToString(); {$ENDIF CLR} end; |