Get the length of arrays and a string

CK CK 3788 
Created at
Updated at  
1,745 0 0

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 Dialog Total number of elements in array strlen Facebook X
Comments 0
  1. Delphi Program can command level execution program with hidden mode
    703
  2. How To Turn On/Off Monitor with Delphi
    858
  3. How to get application version number in Delphi
    1,559
  4. The Delphi function to get My Videos folder
    2,343
  5. Get Application Data Path on Delphi
    840
  6. I want to select directory(folder) not file. How can I do that ?
    625
  7. Changing the Title of a Print Dialog in Delphi
    1,098
  8. Auto Logon Programming in Delphi
    1,034
  9. Thread Application Implementation in TThread
    670
  10. Is there directory selection VCL component in Delphi ?
    525
  11. How to launch the external application in Delphi ?
    1,074
  12. How to print external document ?
    423
  13. Delphi API to get windows temporary directory
    587
  14. Delphi API to get the current working directory
    1,254
  15. How to resize PNG file in Delphi ?
    1,227
  16. Delphi Pointer Types
    22,115
  17. How to read/wrtie INI file in Delphi ?
    3,126
  18. How to get file created time, modified time, and last accessed time ?
    3,352
  19. Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ...
    646
  20. When subject is crashing in TIdSMTP VCL
    622
  21. How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
    1,084
  22. How to encode subject content when sending mail with TIdMessage ?
    1,077
  23. Base64 Encoding/Decoding function for Delphi
    1,176
  24. How to send email by TIdSMTP VCL ?
    1,023
  25. How to return exit code such as exit() function in C/C++ ?
    670
  26. How to get parameter string ?
    1,251
  27. Save TBitmap image to Jpeg format image in Delphi
    717
  28. How to get screen resolution in case of using multiple monitors ?
    454
  29. How to turn off monitor ?
    435
  30. Find File at certain directory in Delphi
    441
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    31
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    57
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    51
  4. How do I create animated background for Google Meet?
    23,255
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    273
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    104
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    170
  8. Array of arguments passed to script in PHP
    99
  9. Invalid Auction Storms in Ad Tech
    108
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    209
  11. The Two Clocks of Ad Server Architecture
    78
  12. Frequency Cap Architecture Overview
    527
  13. Collecting Proof-of-Play from 100,000 Screens
    153
  14. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    303
  15. What is RedisVL?
    117
  16. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    247
  17. TPU & GPU Cluster Management Tools
    258
  18. The Concept of Scaffolding in AI Agents
    245
  19. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    598
  20. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    269
  21. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    355
  22. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    207
  23. Machine Learning: Training vs. Ranking
    230
  24. The Continuous Learning Machine: Designing a Loop That Actually Turns
    229
  25. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    204
  26. Designing a Data Curation System Around a Vector Database
    230
  27. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  28. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    674
  29. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    201
  30. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    233