Solved

Dynamic  array dimention

Posted on 2000-03-01
Medium Priority
268 Views
How to create array with dynamic dimention ? Size of array will be defined only after program start.
0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 27

Expert Comment

ID: 2572629
? use a vararray or a tlist or a tstringlist or a hidden tstringgrid
0

LVL 13

Expert Comment

ID: 2572649
Just an example

var a: array of Byte;
i: Integer;
begin
Randomize;
SetLength(a, 25);  // set size to 25 bytes
for i := Low(a) to High(a) do  // itterate the entire array
a[i] := Random(100);
end;
0

LVL 3

Expert Comment

ID: 2572799
if you have D4 and above....

//=============================
interface

type
TMyGrid = array of array of Integer;

var
MyGrid: TMyGrid; // declares a two-dimensional array of integers.

implementation

// To instantiate, call SetLength with two integer arguments.
// For example, if x and y are integer-valued variables,
// SetLength(Grid, x, y);
// allocates an x-by-y array, and MyGrid[0, 0] denotes an element of the array.
// MyGrid := nil; // deallocates mem

//=============================

Steve
0

LVL 6

Accepted Solution

edey earned 90 total points
ID: 2572957
Or for D2&D3:

type
TIntegerArray = array[0..0] of integer;
PIntegerArray = ^TIntegerArray;

....

var
ints : PIntegerArray;
index : integer;
begin
getMem(ints,sizeOf(integer)*100);
for index := 0 to 99 do
ints[index] := index*index;
//ints is now an array of 100 integers
//containing the squares of 0..99
dispose(ints);
end;

GL
Mike
0

Author Comment

ID: 2573025
Thank you all!
0

LVL 6

Expert Comment

ID: 2573296
Glad to be of service :)

GL
Mike
0

LVL 3

Expert Comment

ID: 2573357
Nice one edey!
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, thâ€¦
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi databaseâ€¦
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (httpsâ€¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrâ€¦
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.