problem with dynamic array of dynamic array

var
 a:array of array of integer;

begin
 setlength(a,2);
setlength(a[0],1);
setlength(a[1],2);
a[0,0]:=1;  //it is ok
a[0,1]:=2;  //it is not ok

in my understanding a[0,1]:=2 is not ok because a[0]  has only one element as i declared setlength(a[0],1)  so i dont understand why this code exemple is compiled and run just fine ?
0
Yossi
7/16/2011 3:54:19 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

4 Replies
636 Views

Similar Articles

[PageSpeed] 57

> {quote:title=Yossi Rozenberg wrote:}{quote}
> in my understanding a[0,1]:=2 is not ok because a[0]  has only one element as i declared setlength(a[0],1)  so i dont understand why this code exemple is compiled and run just fine ?

By default, access to array elements are not checked at compile time.

a[0,1] will compile just fine.

If RANGE CHECKING option is not set, which is the default, it will even run.
If you set range checking, an error will be raised at runtime. But code will be slower.
0
Arnaud
7/16/2011 6:00:15 AM
Yossi Rozenberg wrote:

> var
>  a:array of array of integer;
> 
> begin
>  setlength(a,2);
> setlength(a[0],1);
> setlength(a[1],2);
> a[0,0]:=1;  //it is ok
> a[0,1]:=2;  //it is not ok

Assuming that, with "it is not ok", you mean you get an error, that is
correct. a[0] is an array with ONE element, and that is a[0,0]. a[1]
has TWO elements, a[1,0] and a[1,1]. There is no a[0,1].

In other words, the only elements allocated are a[0,0], a[1,0] and
a[1,1]. Accessing any other element should cause an error (if you
didn't disable range checking).

-- 
Rudy Velthuis

"Human history becomes more and more a race between education 
 and catastrophe." -- H. G. Wells (1866-1946)
0
Rudy
7/16/2011 12:48:42 PM
<Yossi Rozenberg> wrote
> var a: array of array of integer;
>...

Yossi, 
This seems like a technical question.  Maybe it should have been 
posted in group: embarcadero.public.delphi.language.delphi.general
Rgds, JohnH
0
John
7/16/2011 2:20:30 PM
> {quote:title=John Herbster wrote:}{quote}
> <Yossi Rozenberg> wrote
> > var a: array of array of integer;
> >...
> 
> Yossi, 
> This seems like a technical question.  Maybe it should have been 
> posted in group: embarcadero.public.delphi.language.delphi.general
> Rgds, JohnH

sorry,  i think you right (i  made a mistake in the location choosing).
anyway thanks to all who helped me here.
0
Yossi
7/16/2011 2:28:00 PM
Reply:

Similar Artilces:

MOVED: problem with dynamic array of dynamic array
Moved to: embarcadero.public.delphi.language.delphi.general or: https://forums.embarcadero.com/thread.jspa?threadID=57076 -- Rudy Velthuis Rudin's Law: In a crisis that forces a choice to be made among alternative courses of action, people tend to choose the worst possible course. ...

Dynamic Arrays / Static Arrays
If I call SetLength on a dynamic array, does it become more or less a static array? In use is there much difference between a dynamic and a static array? The reason I ask is becaue I don't seem to have had much use for dynamic arrays in what I've created in the past but due to a change of approach in one program I now need to declare an array without knowing how many elements it will have. In the previous incarnation I always knew in advance that the array would have 15 elements. I don't know why I've not had to ask this question before, but as usual, when I do have to...

Arrays, Arrays, Arrays
I mainly come from a JScript classic ASP background and I'm liking both C#.net and JScript.net. Now I have to say... "What's happened to arrays?" They used to be so flexible and easy to use. Here are my quick questions... Am I allowed to create an array with a non specified length so that I can add to it? If not then how can I modify an array's length? Can I create an array with a named index eg myArray["apple"] = "tasty"; or is the hash table the equivalent for this now? The classic array methods and properties like pop(), push(), length etc... are ...

AllocMem vs Dynamic Array Speed Test (see .Delphi.General)
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_3c5a0.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" --JivePart=_3c5a0.zeB8CwDOH5aMJzMl Content-Type: application/zip; name="AllocMem Speed Test.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="AllocMem Speed Test.zip" UEsDBBQAAAAIACxKyDybs5DTnQAAAAwBAAANAAAAU3BlZWRUZXN0LmRwcmVOSwrCMBDdB3KHWQhV KTmAxYUIBRci1FxgascSbNMwSTeW3t3GRakWZvF+83iOu5qxhbsjqjT5k...

array of dates placed in dynamic array
Ok---I want to take an array of dates and load it into a dynamic array.  The reason I have duplicate dates in my dataset.  This means when it loads the 2nd or even 3rd date for that date. It just overrides the previous date's text.  So I need to load the date along w/the string into a dynamic array, so I can access it Right now to load the date I do the following: For rowCount = 0 To DsVacationData1.RequestDataManager.Rows.Count - 1row = DsVacationData1.RequestDataManager.Rows(rowCount)sDate = CStr(CDate(row.Item(1)))sEmployee = row.Item(8).ToString + " " + row.Item(9).ToStr...

Problem with dynamic string array
Hi All I do have the following problem I declare a string array here private Details : array of array of String; //Details : Array[0..53,0..3] of string; somewhere in the code I assign values to it SetLength(Details, 53,3); for i := 0 to 52 do begin Details[i,0] := '-'; Details[i,1] := IntToStr(i); Details[i,2] := FullName; Details[i,3] := prio; end; everything is fine, but if I then call via a Button Event //Details := nil; Release; I got Exeptions. If I do this with a non Dynamic Array everything is fine, what do I...

referring to an array in an array of arrays
How can I get at an array in an array of arrays? I'm creating the arrays using: $fComments[$i++] = [ @comments ]; Now I want to get back what I put in: print "$fComments[0]\n"; but this prints ARRAY(0x107671f0). How do I follow that pointer? (I really think we need a pre-beginners list... =) TIA. - B You can try something like this: print "@{$fComments[0]}\n"; Which will attempt to dereference the array at $fComments[0]. -----Original Message----- From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com] Sent: Tue...

Concatenating arrays from arrays of arrays
Hello - I am trying to accumulate items in a flat list (array) by concatenating on to it the scalars contained in arrays which in turn are contained in arrays. The data is to be read in from a file rather than existing as literals in my code. Everything I try either crashes the computer or gives me an array of arrays instead of a flat list. I have been programming in Unicon which has a concatenate operator, but Perl makes very heavy weather of nested list management. Should I switch to Lisp, or is there a way of doing what I want to do in Perl? Regards _John Sampson_ On...

How to unshift to an array in an array of arrays?
How to unshift to an array in an array of arrays? > -----Original Message----- > From: Angerstein [mailto:ang@nmc-m.dtag.de] > Sent: Wednesday, August 28, 2002 6:12 AM > To: beginners@perl.org > Subject: How to unshift to an array in an array of arrays? > > > How to unshift to an array in an array of arrays? $ perl -d -e 1 ..... DB<1> @aoa = ([qw(foo bar baz)]) << create array of arrays DB<2> x @aoa 0 ARRAY(0x80f82dc) 0 'foo' 1 'bar' 2 'baz' DB<3> unshift @{$aoa[0]}, 'qu...

Dynamic Array
Hi I have the following code: Public Class WebForm1 Inherits System.Web.UI.Page Public partitions(50, 3) As String Dim lblNoParts, lblNoParts2 As New Label #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm Protected WithEvents Button2 As System.Web.UI.WebControls.Button ...

Array of Arrays
Hi, I am looking for a way to create an array of arrays which needs to be passed to Oracle database to minimize the round trips to hte server. I was successful in sending simple arrays so far but no idea on how to create array of arrays in PB. I have used structures to simulate this but looks like I can't send the structure to Oracle. Anyone has any suggestions? Thanks, Anil Please don't cross-post. On 3 Mar 2005 14:02:47 -0800, Anil wrote: >Hi, > >I am looking for a way to create an array of arrays which >needs to be passed to Oracle database t...

Dynamic Array
Any idea how to create a large dynamic array? Normally I use MyArray: Array of Double; SetLength(MyArray, SomeLength); But SomeLength in SetLength cannot be large than an Integer. I need to create an array of 12288 by 17000 16 bit. Is this possible? Can I allocate a large block of memory? Peter. Edited by: Peter Herijgers on Jan 30, 2009 2:36 AM > But SomeLength in SetLength cannot be large than an Integer. And thats good since the total amount of system memory you can address is 2GB (3GB at most). So you are only allowed to allocate (2GB div sizeof(double)) elem...

Dynamic Arrays
I needed to create a dynamic, multi-deminsional array which PB 6.0 won't allow. I tried setting up a structure with the necessary elements and setting up a single deminsion, dynamic array and it would appear that PB 6.0 won't allow structures as elements of arrays. To resolve this delimma I set up a btree list using a user object with the necessary instance variables and events. I haven't resolved all of the problems this has created yet. My question is: Is this the best way to solve this problem? Is there any other way to create a dynamic, multi-deminsional array? ...

[@array] and \@array
Given the case, my @array = (1,2,3,4); my $var1 = [@array]; my $var2 = \@array; What's the difference between $var1 and $var2? Are they all refered to @array? Thanks guys. On 3/22/07, Jm lists <practicalperl@gmail.com> wrote: > Given the case, > > my @array = (1,2,3,4); > my $var1 = [@array]; > my $var2 = \@array; > > What's the difference between $var1 and $var2? > Are they all refered to @array? > Thanks guys. $var2 is a reference to @array. $var1 is a reference to new array. Observe #!/usr/bin/perl use strict; use war...

Web resources about - problem with dynamic array of dynamic array - embarcadero.delphi.general

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

Malcolm Turnbull's first 100 days as Prime Minister: Successes and problems
December 23 marks 100 full days as Prime Minister for Malcolm Turnbull. How has he fared? Lisa Cox looks at his successes and the headaches. ...

Malcolm Turnbull's first 100 days as Prime Minister: Successes and problems
December 23 marks 100 full days as Prime Minister for Malcolm Turnbull. How has he fared? Lisa Cox looks at his successes and the headaches. ...

Why we all have a problem with expensive drugs
We are all paying for the pharmaceutical industry's laws and arrangements that guarantee it profitability.

Malcolm Turnbull's first 100 days as Prime Minister: Successes and problems
December 23 marks 100 full days as Prime Minister for Malcolm Turnbull. How has he fared? Lisa Cox looks at his successes and the headaches. ...

This one app could solve your most frustrating home Wi-Fi problems
So you've just set up your home Wi-Fi network but for some reason you're having trouble getting your PC to connect to the network. It could very ...

"When there’s a problem, people need someone or something to blame. Among L.A. residents peeved with ...
... they’d take their garden-wrecking, loudly squawking, prolifically pooping selves and fly the coop...." Did you know L.A. has a peacock problem ...

Merkel-Enhanced Migration Problem: Million Refugees Hit Europe, 80% Through Greece by Boat; Turkish Mafia ...
... made their way to Europe this year. Every country is complaining now, even Germany. So why isn't anything concrete being done? Why the Problem ...

Maps Minutes Hack #7: No signal, no problem. Navigate your holiday travels with Google Maps offline
Part of our series on how to save time this holiday season with Google Maps. This time of year, millions take a road trip home for the holidays ...

Chicago-Bound Southwest Flight Returns To Oakland With Landing Gear Problem
... flight headed to Chicago was forced to return to Oakland, California, and make an emergency landing on Wednesday, due to a landing gear problem. ...

Resources last updated: 12/24/2015 10:11:49 PM