Trying to move Delphi 2007 project to XE4. In Delphi 2007 I was using function that reads byte array from socket using Indy directly. I passed AnsiString casted to array of byte to var parameter of this function:
var data:AnsiString;
AContext.Connection.IOHandler.ReadBytes(TIDBytes(Data), PacketLength-PacketLengthDelta-1, False);
In Dlphi XE when I try to concatinate Data to another string I got access violation error.
Now I'm trying to simulate this problem in more simple code:
TIdBytes = array of Byte;
procedure fill(var b: TIDBytes);
begin
setlength(b,5);
b[0]:=61;
b[1]:=61;
b[2]:=61;
b[3]:=61;
b[4]:=61;
//original function used move function
end;
procedure TMainForm.FormCreate(Sender: TObject);
var s: ansistring ;
begin
fill( TIDBytes(s) );
Showmessage(s);
end;
Now I expect to see something like ==== in message box, but I got empty one. I supposed that XE AnsiString acts the same like Delphi 2007 Ansistring and you can use them like byte array in both cases.
What is the best way to solve filling AnsiString with bytes problem?