![]() |
Delphi-Version: 2010
Move() von PAnsiChar in ein Array Of Byte
Folgendes Problem:
Ich habe einen X Byte langes PAnsiChar. Dieses will ich einmal direkt auf Festplatte schreiben und einmal in ein lesbares Format konvertieren und dann ausgeben. Das Schreiben auf Platte funktioniert gut und wuppt meiner Meinung nach auch korrekte Daten auf Festplatte.
Delphi-Quellcode:
,
thisEvent.Sysex: PAnsiChar
Delphi-Quellcode:
thisEvent.SysexLength: Integer
Delphi-Quellcode:
Nun moechte ich die gleichen Daten auch lesbar ausgeben (Hex).
fsSysex := TFileStream.Create(GetNextDumpFileName, fmCreate, fmShareDenyWrite);
try fsSysex.Write(thisEvent.Sysex^, thisEvent.SysexLength); finally fsSysex.Free; end;
Delphi-Quellcode:
SysExArray: Array of Byte;
Delphi-Quellcode:
ByteArrayToHexString sieht so aus:
SetLength(SysExArray, thisEvent.SysexLength);
Move(thisEvent.Sysex^, SysExArray[0], thisEvent.SysexLength); DbgOut(ByteArrayToHexString(SysExArray))
Delphi-Quellcode:
Frage ist jetzt: Was mach ich bei Move() falsch?
function TfrmMain.ByteArrayToHexString(const InArr: array of Byte): string;
var tmpStrList: TStringList; i: Integer; begin tmpStrList := TStringList.Create; try for I := Low(InArr) to High(InArr) do begin tmpStrList.Append(IntToHex(InArr[i], 2)); end; tmpStrList.Delimiter := ' '; Result := tmpStrList.DelimitedText; finally tmpStrList.Free; end; end; Ein Hexeditor zeigt mir die Datei so an:
Code:
Mein ByteToArrayToHexString spuckt aber aus:
F0 7E 00 06 01 F7
Code:
Ersteres ist richtig (gueltige MIDI SysEx-Nachricht), zweiteres nur Müll.
40 6A AF 00 A0 D9
Hab jetzt schon mit CopyMemory & Co. experimentiert, aber irgendwie klappts net :| |
AW: Move() von PAnsiChar in ein Array Of Byte
Funktioniert problemlos. :gruebel:
Delphi-Quellcode:
var thisEvent_Sysex: PAnsiChar;
thisEvent_SysexLength: Integer; SysExArray: Array of Byte; procedure TForm1.FormCreate(Sender: TObject); begin thisEvent_Sysex := #$F0#$7E#$00#$06#$01#$F7; thisEvent_SysexLength := 6; SetLength(SysExArray, thisEvent_SysexLength); Move(thisEvent_Sysex^, SysExArray[0], thisEvent_SysexLength); ShowMessage(ByteArrayToHexString(SysExArray)); end; |
AW: Move() von PAnsiChar in ein Array Of Byte
Warum so umständlich?
du hast ein PAnsiChar und die zugehörige Länge also warum nicht so
Delphi-Quellcode:
Gruß
dummystr:='';
for i:=0 to länge-1 do dummystr:=inttohex(byte(pAnsiChar^[i]),2); K-H |
AW: Move() von PAnsiChar in ein Array Of Byte
Zitat:
Delphi-Quellcode:
SetString() ist nicht so gefährlich wie Move().
// vereinfachter Code
var SysExText:Ansistring; .. SetString(SysExText, thisEvent.Sysex, , thisEvent.SysexLength); DbgOut(StringToHexString(SysExText)); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:25 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