![]() |
Array of Byte in String wandeln, Accessciolation
Guten Morgen miteinander
Wie es der Titel schon sagt, würde ich gerne ein Array of Byte (ASCII) in einen String wandeln. Das hab ich mir dann so vorgestellt:
Code:
Nur bekomme ich immer eine Exception...Repeat rData[i+1] := Chr(FT_In_Buffer[i]); //EAccessviolation i := i+1; until Length(rData) = 22; Die Werte im Array sind gültig. In die andere Richtung klappts wunderbar.
Code:
Gruss
Repeat
FT_Out_Buffer[i-1] := Ord(sData[i]); i := i+1; until Length(sData+1) = i; |
Re: Array of Byte in String wandeln, Accessciolation
So sollte es funktionieren:
Delphi-Quellcode:
Test:
function BytesToStr(const ba; size: cardinal): string;
begin SetLength(Result, size); Move(ba, Result[1], size); end;
Delphi-Quellcode:
Grüße vom marabu
const
CbaSize = 50; var ba: array [1..CbaSize] of byte; s: string; begin for i := Low(ba) to High(ba) do ba[i] := 48 + i mod 10; s := BytesToStr(ba, CbaSize); Write(Length(s), ': ', s); ReadLn; end; |
Re: Array of Byte in String wandeln, Accessciolation
danke für die Antwort
Ich probier das mal zu implementieren. Aber wieso funktioniert meine Methode nicht? |
Re: Array of Byte in String wandeln, Accessciolation
Weil du die Länge des Strings vorher bestimmen musst (->SetLength)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:02 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz