[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.246 SetLength

### Synopsis

    procedure SetLength (var S: String; NewLength: Integer);

### Description

``SetLength'` explicitly assigns a new length ``NewLength'` to the string parameter `S`. The contents of the string is not changed; if the operation increases the length of the string, the characters appended at the end are undefined.

### Conforming to

``SetLength'` is a Borland Delphi 2.0 extension.

### Example

    program SetLengthDemo;

    var
      S: String (26);

    begin
      S := 'Hello, world!';
      SetLength (S, Length ('Hello'));
      WriteLn (S);                                           { 'Hello' }

      SetLength (S, 26);
      WriteLn (S);                     { 'Hello, world!(%$xy"!#&~+(/]' }
                                { undefined characters ^^^^^^^^^^^^^^  }

      SetLength (S, 42);       { The overflow is *not* (yet) detected. }
      WriteLn (S);        { This might cause a runtime error or crash. }
    end.

### See also

section 9.133 Length, section 9.268 String.

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html