Your code skips SetLength, fixed version:
Init( msg: PCHAR)
var
myStr: String;
begin
SetLength(myStr, 256);
for i:= 1 to 256 do
begin
myStr[i] := msg[i-1];
end;
end;
Appointment can be performed more efficiently, as already mentioned.
Update
SetLength allocates 256 characters + 0 termination for myStr; without SetLength your code is an error: it writes to wild address and, finally, leads to access violation.
kludg source
share