Search results for 'element count in array'. 1 post(s) found.
- 2009/08/22 Get the length of arrays and a string
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;
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;
Another posts included in "Delphi"
| How to resize PNG file in Delphi ? (0) | 2009/09/03 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| Delphi Pointer Types (0) | 2009/08/22 |
| How to read/wrtie INI file in Delphi ? (0) | 2009/08/21 |
| How to get file created time, modified time, and last accessed time ? (0) | 2009/08/19 |
| Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (0) | 2009/07/20 |
| When subject is crashing in TIdSMTP VCL (0) | 2009/07/20 |

Prev

Rss Feed