The length function returns either the number of characters in Source String, or the number of elements in Source Array.
Notes: Arrays start at index=0 by default, So the length of such an array is 1 more than the highest index.
Following is the simple example to get the length of arrays and a string var
openArray : array of char;
fixedArray : array[2..4] of Integer;
multiArray : array[2..4, 1..9] of Integer;
shortStr : shortstring;
longStr : string;
i : Integer;
begin
// Define the length of the open array
SetLength(openArray, 17);
// Show the length of the arrays
ShowMessage('Length of openArray = '+IntToStr(Length(openArray)));
ShowMessage('Length of fixedArray = '+IntToStr(Length(fixedArray)));
ShowMessage('Length of multiArray = '+IntToStr(Length(multiArray)));
// Assign to the strings
shortStr := 'ABCDEFGH';
longStr := '12345678901234567890';
ShowMessage('Length of shortStr = '+IntToStr(Length(shortStr)));
ShowMessage('Length of longStr = '+IntToStr(Length(longStr)));
// Display one letter at a time from the short string
for i := 1 to Length(shortStr) do
ShowMessage('Letter '+IntToStr(i)+' = '+shortStr[i]);
end;
Tags: Browser Name Browser Version Delphi Dialog Total number of elements in array strlen
|