Sign in Join
FPDoc Onlineexperiment

NewStr function

In unit Objects

Allocate a copy of a shortstring on the heap.

Declaration

pascal
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

Example: ex40

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

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.