nsascape.blogg.se

Delphi xe10 record
Delphi xe10 record





delphi xe10 record

The compiler does the math to turn an array index into a pointer to the into a pointer to a single element in the array.ĭynamic arrays, on the other hand, add a level of indirection.

delphi xe10 record

Static arrays are really just pointers to a contiguous area of memory that was allocated to hold the right number of elements for the array. So, how does all this magic that makes java developers jealous happen under the hood? With dynamic arrays, it’s easy! Just call SetLength again, then you can use the newly allocated elements in your array: SetLength(Nums, 16) Įven after you’ve changed the size, the original elements are still there – no data is lost (OK, data *IS* lost if you resize an array to be SMALLER than it was before), and you just continue on your way. What happens if, during the course of our program running, the size of the array needs to change? With static arrays, this simply wasn’t possible. (Note that dynamic arrays are zero-indexed, so the highest index in the array is Length – 1) Now that the length is set, we can assign values to the array, just like we could with a static array: Nums := 1 Before we can put something in the array, we need to set its length using the conveniently named SetLength procedure: SetLength(Nums, 8) This creates a reference to the array, but doesn’t actually allocate any memory for the contents of the array. You don’t need to declare its size when you write your code, and you can programatically change the size of the array. Way back in Delphi 4, dynamic arrays were added to the language. In the old days, when you needed an array in your Delphi program, the array had to be static, which meant its size had to be known at the time you wrote your code. If you’re already comfortable with the use of dynamic arrays, you can skip this section: Let’s talk for a bit about how dynamic arrays work “behind the scenes.” First, a dynamic array primer.







Delphi xe10 record