Difference between revisions of "SetLength"

From SCAR Divi Manual
Jump to: navigation, search
(Created page with "==Definition== <source lang="scar" lines="false"> procedure SetLength(var s; NewLength: Integer); </source> ==Availability== SCAR Divi 3.00 > Current ==Description== Sets the l...")
 
 
Line 8: Line 8:
  
 
==Description==
 
==Description==
Sets the length of an array/string passed in '''s''' to a given length '''NewLength'''.
+
Sets the length of an [[arrays|array]]/[[string]] passed in '''s''' to a given length '''NewLength'''.
  
 
==Example 1 (Arrays)==
 
==Example 1 (Arrays)==

Latest revision as of 13:16, 16 November 2011

Definition

procedure SetLength(var s; NewLength: Integer);

Availability

SCAR Divi 3.00 > Current

Description

Sets the length of an array/string passed in s to a given length NewLength.

Example 1 (Arrays)

var
  TIA: TIntArray;

begin
  SetLength(TIA, 5);
  TIA[0] := 2;
  TIA[1] := 4;
  TIA[2] := 6;
  TIA[3] := 8;
  TIA[4] := 10;
  WriteLn(TIAToStr(TIA));
end.

Output:

2,4,6,8,10

Example 2 (Strings)

var
  s: string;

begin
  SetLength(s, 5);
  s[1] := 'a';
  s[2] := 'b';
  s[3] := 'c';
  s[4] := 'd';
  s[5] := 'e';
  WriteLn(s);
end.

Output:

abcde

See Also