Solved

Dynamic  array dimention

Posted on 2000-03-01
7
261 Views
Last Modified: 2010-10-05
How to create array with dynamic dimention ? Size of array will be defined only after program start.
0
Comment
Question by:Vadik
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2572629
? use a vararray or a tlist or a tstringlist or a hidden tstringgrid
0
 
LVL 13

Expert Comment

by:Epsylon
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

by:SteveWaite
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
edey earned 30 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

by:Vadik
ID: 2573025
Thank you all!
0
 
LVL 6

Expert Comment

by:edey
ID: 2573296
Glad to be of service :)


GL
Mike
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 2573357
Nice one edey!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 86
Making delphi communicate with a c# service 16 88
Tviruailstringtree sort multi columns on header click 1 52
SUM 2 INTEGER ARRAYS INTO 1 10 93
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now