Ok kein Problem.
Dieses Beispiel mit dem statischen Array funktioniert ohne Probleme.
In Edit3.Text befindet sich ein 6 Stellen langes Wort
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var data: Array[0..19] of Byte;
bytes: TIdBytes;
i: integer;
begin
//setlength(data, length(Edit3.Text) + 14);
// ReqSize
data[0] := length(Edit3.Text) + 10;
data[1] := 0;
data[2] := 0;
data[3] := 0;
// ReqID
data[4] := 0;
data[5] := 0;
data[6] := 0;
data[7] := 0;
// ReqType
data[8] := 3;
data[9] := 0;
data[10] := 0;
data[11] := 0;
// ReqBody
for i := 1 to length(Edit3.Text) do
data[11 + i] := TEncoding.Default.GetBytes(Edit3.Text[i])[0];
// Null Terminator Body
data[High(data) - 1] := 0;
// Null Terminator Req
data[High(data)] := 0;
//showmessage(IntToStr(length(data)));
SetLength(bytes, length(data));
move(data, bytes[0], length(data));
IdTCPClient1.IOHandler.Write(bytes);
end;
Hier das Beispiel mit einem dynamischen Array.
Hier bekomme ich nur wirres Zeug angezeigt.
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var data: Array of Byte;
bytes: TIdBytes;
i: integer;
begin
setlength(data, length(Edit3.Text) + 14);
// ReqSize
data[0] := length(Edit3.Text) + 10;
data[1] := 0;
data[2] := 0;
data[3] := 0;
// ReqID
data[4] := 0;
data[5] := 0;
data[6] := 0;
data[7] := 0;
// ReqType
data[8] := 3;
data[9] := 0;
data[10] := 0;
data[11] := 0;
// ReqBody
for i := 1 to length(Edit3.Text) do
data[11 + i] := TEncoding.Default.GetBytes(Edit3.Text[i])[0];
// Null Terminator Body
data[High(data) - 1] := 0;
// Null Terminator Req
data[High(data)] := 0;
//showmessage(IntToStr(length(data)));
SetLength(bytes, length(data));
move(data, bytes[0], length(data));
IdTCPClient1.IOHandler.Write(bytes);
end;