Unit 'Objects' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

NewStr

Allocate a copy of a shortstring on the heap.

Declaration

Source position: objects.pp line 710

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 based 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.

Documentation generated on: Nov 23 2024