Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic  array dimention

Posted on 2000-03-01
7
Medium Priority
?
269 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Accepted Solution

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

876 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