What is the preferable way of getting a dynamic length string from memory (which is also compatible with XE and XE7 - the two IDEs I use)?
What is the preferable way of getting a dynamic length string from memory (which is also compatible with XE and XE7 - the two IDEs I use)?
I have found:
function AMethod(nBuffer : Integer) : string;
var
buffer: array of Char;
nBuffer: Cardinal;
begin
SetLength(buffer, nBuffer);
GetAStringFromSomewhere(PChar(buffer), nBuffer);
Result := StrPas(PChar(buffer));
end;
and
function AMethod(nBuffer : Integer) : string;
var
buffer: array of Char;
nBuffer: Cardinal;
begin
SetLength(buffer, nBuffer);
GetAStringFromSomewhere(PChar(buffer), nBuffer);
SetString(Result, PChar(buffer), nBuffer (?? should be a length)); // Something like this
end;
There is another one which I can't think of (which takes a TArray - I think)...
Any others?
I have found:
function AMethod(nBuffer : Integer) : string;
var
buffer: array of Char;
nBuffer: Cardinal;
begin
SetLength(buffer, nBuffer);
GetAStringFromSomewhere(PChar(buffer), nBuffer);
Result := StrPas(PChar(buffer));
end;
and
function AMethod(nBuffer : Integer) : string;
var
buffer: array of Char;
nBuffer: Cardinal;
begin
SetLength(buffer, nBuffer);
GetAStringFromSomewhere(PChar(buffer), nBuffer);
SetString(Result, PChar(buffer), nBuffer (?? should be a length)); // Something like this
end;
There is another one which I can't think of (which takes a TArray
Any others?
Comments
Post a Comment