Solved

Help with Dynamic Arrays.

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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