help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'Objects' (#rtl)

NewStr

Allocate a copy of a shortstring on the heap.

Declaration

Source position: objects.pp line 620

function NewStr(

  const S: String

):PString;

Description

NewStr makes a copy of the string S on the heap, and returns a pointer to this copy. If the string is empty then Nil is returned.

The allocated memory is not based on the declared size of the string passed to NewStr, but is baed on the actual length of the string.

Errors

If not enough memory is available, an 'out of memory' error will occur.

See also

DisposeStr

  

Dispose of a shortstring which was allocated on the heap.

SetStr

  

Allocate a copy of a shortstring on the heap.

Example

Program ex40;

{ Program to demonstrate the NewStr function }

Uses Objects;

Var S : String;
    P : PString;

begin
  S:='Some really cute string';
  P:=NewStr(S);
  If P^<>S then
    Writeln ('Oh-oh... Something is wrong !!');
  DisposeStr(P);
end.

Notes

 No notes exist for this page yet. 





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505