Helpful Information
 
 
Category: Delphi Programming
deleting array contents

hi, i need to finish my program by sunday night, and its now sat afternoon, but i need serious help! i have an array to store records, but one of the options i wanted to include was to delete one of the records in the array. The prblem is that i dont know how! is there some kind of function, or do i have to type out some code? the only way i couls see past it was to overwrite the next record into the array onto the one that i want to delete. the problem with that is that then i have two records in a row that are identical.

Please help if you can, i'm getting really desperate! either post a reply or email me on imperial_overlord@hotmail.com. Thanks!

mike.

Normally we don't do homework on the forum, but since you've actually shown some effort, I'll give you a hand. Let's say the array is 12 elements long and you want to delete the element at position 5. What you want to do is copy element 6 to element 5, element 7 into element 6, element 8 into element 7 and so on, all the way to the end of the array. To do this, the trick is to use a for, repeat or while loop to do it. I'll give you some pseudo code (assuming index = 5 and arraysize = 12)


{ Shift all the elements by 1 }
for i := index to arraysize - 1 do
array[i] := array[i+1];

array[arraysize] := 0; { Blank out the last element }

hey!

thanks for trying, but i've handed my project in already! And we were allowed to do ask for help from other people so long as we said so in the project! At least now i know for future reference!

mike










privacy (GDPR)