Solved

Dynamic  array dimention

Posted on 2000-03-01
7
259 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now