In fact, in:
unsigned char *buf=NULL;
buf=new unsigned char[SPS*2];
The first assignment *buf=NULL
can be translated as buf := nil
but it is pure dead code, since buf
pointer content is immediately overwritten by the new
function.
So your C code may be translated as such:
var buf: PAnsiChar;
i: integer;
begin
Getmem(buf,SPS*2);
for i := 0 to SPS*2-1 do
buf[i] := #2;
...
Freemem(buf);
end;
A more Delphi-idiomatic version may be:
var buf: array of AnsiChar;
i: integer;
begin
SetLength(buf,SPS*2);
for i := 0 to high(buf) do
buf[i] := #2;
...
// no need to free buf[] memory (it is done by the compiler)
end;
or directly:
var buf: array of AnsiChar;
i: integer;
begin
SetLength(buf,SPS*2);
fillchar(buf[0],SPS*2,2);
...
// no need to free buf[] memory (it is done by the compiler)
end;