Solved

Dynamic  array dimention

Posted on 2000-03-01
7
265 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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