Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 108099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:51:30+00:00 2026-05-11T01:51:30+00:00

I originally had an array[1..1000] that was defined as a global variable. But now

  • 0

I originally had an array[1..1000] that was defined as a global variable. But now I need that to be n, not 1000 and I don’t find out n until later. I know what n is before I fill the array up but I need it to be global therefore need a way to define the size of a global array at run time.

Context is filling an array with a linear transformation of the bytes in a file. I don’t know how big the file is until someone wants to open it and the files can be of any size.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:51:31+00:00Added an answer on May 11, 2026 at 1:51 am

    As of Delphi 4, Delphi supports dynamic arrays. You can modify their sizes at run time and they will retain the data you stored in other elements at the old size. They can hold elements of any homogeneous type, including records and other arrays. You can declare a dynamic array the same as you declare normal, ‘static’ arrays, but simply omit the array bounds:

    var   ArthurArray: array of TForm; 

    Although static arrays allow you to specify both the lower and upper bound, the low index of a dynamic array is always zero. The high index is given by the High function, which always returns one less than the length of the array. For any dynamic array x, High(x) = Length(x)-1.

    A global variable can be accessed by any code, including local procedures.

    A global variable of dynamic-array type will be initialized to be an empty array. Its length will be zero and High called on that array will be -1. Low on that array will still return zero.

    At any time, you may resize a dynamic array. Use the SetLength function, just as you can do with strings:

    var   NumElements: Integer; begin   NumElements := GetNumberOfArthurForms();   SetLength(ArthurArray, NumElements); end; 

    If you have a multidimensional array, you can set their lengths in a loop:

    var   matrix: array of array of Double;   i: Integer; begin   SetLength(matrix, height);   for i := 0 to height - 1 do     SetLength(matrix[i], width); end; 

    There’s a shortcut for that to set the lengths of all the inner arrays at once:

    begin   SetLength(matrix, height, width); end; 

    Like I mentioned, dynamic arrays keep their old values when you resize them:

    var   data: array of string; begin   SetLength(data, 2);   data[1] := 'foo';   SetLength(data, 20);   Assert(data[1] = 'foo'); end; 

    But if you shorten the array, any elements that resided beyond the new last element are gone forever:

    begin   SetLength(data, 20);   data[15] := 'foo';   SetLength(data, 2);   // data[15] does not exist anymore.   SetLength(data, 16);   writeln(data[15); // Should print an *empty* line. end; 

    My demonstrations above used strings. Strings are special in Delphi; they’re managed by the compiler through reference counts. Because of that, new dynamic-array elements of type string are initialized to be empty. But if I had used integers instead, there would be no guarantee of the values of new elements. They might be zero, but they might be anything else, too, just like the initial values of standalone local variables.

    The Delphi 7 help files are very good, I’m told. Please read more about dynamic arrays there. You can find demonstrations of their use throughout the VCL and RTL source code provided in your Delphi installation, as well as in nearly any Delphi code example produced in the last 10 years.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The schemas don't exist as an xml file. Schemas are… May 11, 2026 at 11:56 am
  • added an answer Your initial attempt at 4 words before/after wasn't too far… May 11, 2026 at 11:56 am
  • added an answer I'm assuming you must issue hundreds of commands to the… May 11, 2026 at 11:56 am

Related Questions

I originally had an array[1..1000] that was defined as a global variable. But now
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I originally asked this question , but in finding an answer, discovered that my
I originally used WebRequest and WebResponse to sent Http Post Messages. Always I got
When I originally was introduced to Mocks I felt the primary purpose was to
I have a list of variable names, like this: ['foo', 'bar', 'baz'] (I originally
Originally I thought to ask if there would be an easy way to provide
Originally I though I'll just take a screenshot of my app on the iPhone
I have some code which I did not originally create that uses _beginthreadex and
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.