Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Array of Byte in String wandeln, Accessciolation (https://www.delphipraxis.net/49148-array-byte-string-wandeln-accessciolation.html)

Selecta 6. Jul 2005 08:25


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:
 
Repeat
  rData[i+1] := Chr(FT_In_Buffer[i]); //EAccessviolation
  i := i+1;
until Length(rData) = 22;
Nur bekomme ich immer eine Exception...
Die Werte im Array sind gültig.


In die andere Richtung klappts wunderbar.
Code:
Repeat
  FT_Out_Buffer[i-1] := Ord(sData[i]);
  i := i+1;
until Length(sData+1) = i;
Gruss

marabu 6. Jul 2005 08:34

Re: Array of Byte in String wandeln, Accessciolation
 
So sollte es funktionieren:

Delphi-Quellcode:
function BytesToStr(const ba; size: cardinal): string;
begin
  SetLength(Result, size);
  Move(ba, Result[1], size);
end;
Test:

Delphi-Quellcode:
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;
Grüße vom marabu

Selecta 6. Jul 2005 09:12

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?

Jasocul 6. Jul 2005 09:14

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