-
Notifications
You must be signed in to change notification settings - Fork 7
API.CString
Ivan Semenkov edited this page Oct 24, 2021
·
4 revisions
API.CString is a wrapper around C language API cstring char *
value.
uses
utils.api.cstring;
type
API = class
type
CString = class
end;
PAnsiStringWrapper class is a thin wrapper around PAnsiChar which delete allocated memory on destructor.
uses
utils.api.cstring;
type
API = class
type
PAnsiStringWrapper = class
end;
Return stored in wrapper PAnsiChar value.
property Value : PAnsiChar;
Return stored in wrapper string length.
property Length : Cardinal;
A new wrapper can be created by call its constructor.
Create a empty string.
constructor Create;
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create;
FreeAndNil(str);
end;
Create new string by pascal string
type.
constructor Create (AString : String);
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create('some string value');
FreeAndNil(str);
end;
Create new string by PAnsiChar
type.
constructor Create (AString : PAnsiChar);
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create(PAnsiChar('some string value'));
FreeAndNil(str);
end;
Convert stored value to correct pascal string
value.
function ToString : String;
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create('some string value');
writeln(str.ToString);
FreeAndNil(str);
end;
Convert stored value to correct PAnsiChar
value.
function ToPAnsiChar : PAnsiChar;
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create('some string value');
writeln(str.ToPAnsiString);
FreeAndNil(str);
end;
Allocate memory for new string and convert stored value to correct PAnsiChar
value.
function ToUniquePAnsiChar : PAnsiStringWrapper;
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create('some string value');
writeln(str.ToUniquePAnsiString.Value);
FreeAndNil(str);
end;
Return stored string value length.
function Length : Integer;
uses
utils.api.cstring;
var
str : API.CString;
begin
str := API.CString.Create('some string value');
writeln(str.Length);
FreeAndNil(str);
end;