Solved

Help with Dynamic Arrays.

Posted on 1998-09-26
2
148 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

14 Experts available now in Live!

Get 1:1 Help Now