1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

SetLength

unit
System
category
string handling routines

declaration
procedure SetLength(var S; Length1: Integer [; Lenght2: Integer]);

description
Changes the size of a dynamic array or a string.

S is a string or dynamic-array variable. If S is a multidimensional dynamic array, we can pass on or more lenghts to the procedure.

For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.

example
//create an integer vector of N elements
type
  TVector = array of integer;

procedure SetVector(var V: TVector; N: integer);
var i: integer;
begin
  SetLength(V,N);
  for i:= 0 to N-1 do
    N[i]:= N-1-i; 
end;
//if N=6 then v={5,4,3,2,1,0};

in real code
String Types in Delphi
Understanding and managing string data types in Delphi's Object Pascal. Learn about differences between Short, Long, Wide and null-terminated strings.
Arrays in Object Pascal
Understanding and using array data types in Delphi.

see also
SetString, BoolToStr


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.