Solved

Help with Dynamic Arrays.

Posted on 1998-09-26
2
152 Views
Last Modified: 2010-04-06
Could someone please give me an example of how to reallocate the size of a dynamic array without losing the items currently in the array. What I need to do is declare a dynamic array of records and then increase the size of the array by one every time I need to add a new record.

Thanks

BTW, what's up with the Delphi Debugger? I'm new to Delphi(from VB) and was wondering why the debugger doesn't give more info... like the line that caused the AccessViolation or a least a description of what happened. Do I have something setup wrong or have I found the first drawback to my switch from VB? This might be normal for a non-interpreted language... I'm not sure. But I'll tell you that CPU View doesn't help me at all =)
0
Comment
Question by:Karma121397
2 Comments
 
LVL 2

Expert Comment

by:omsec
ID: 1340868
i think that's like in Basic. If your Array actually contains 50
Elements for example, you can't go below these 50 if you don't want to lose values in the End of the Array.

for more info see Delphi 4 Help

CONTENTS - WHAT'S NEW IN DELPHI 4 - DYNAMIC ARRAYS
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 1340869
Karma,

var testRec : array of record
                         str: string;
                         int: integer;
                       end;

SetLength(testRec,1);
with testRec[0] do begin str:='test'; int:=777 end;
SetLength(testRec,2);
with testRec[1] do begin str:='test2'; int:=778 end;
if (testRec[0].str<>'test') or (testRec[0].int<>777) then
  raise Exception.Create('Aaaaaaahhhrggg... This should not happen!');

Of course, if you now call "SetLength(testRec,1)" the second record (and it's content) is lost. That's what omsec means. But that was not your question, I think...

Normally Delphi should show you the line where the exception happened. Go to menu->project->options/compiler/debug. Make sure you check all checkboxes that Delphi needs to find the exception location. I don't know the exact setting you need. (I've the german version, so the names of the checkboxes differ.)
In the editor you should see a small blue dot/circle before each line that contains code and that is not linked out of the executable.

Regards, Madshi.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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