• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Help with Dynamic Arrays.

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
Karma121397
Asked:
Karma121397
1 Solution
 
omsecCommented:
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
 
MadshiCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now