Solved

Dynamic  array dimention

Posted on 2000-03-01
7
267 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
[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
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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