Deleting a record....HELP 
Author Message
 Deleting a record....HELP

Hi,

This may seem like a stupid question.....
I have an array of records and I know how to add records to that array.
How would I delete a record from that array?

Thanx!

Leonard



Wed, 18 Jun 1902 08:00:00 GMT  
 Deleting a record....HELP

Leonard,

  This is not a stupid question.  There are several different way to do this
depending on you meaning of "delete".  If deleting means just blanking out
the field of the record at index n, then your solution may look something
like this:

type
  MyRecord = record
    Name: string[10];
    Phone: string[12];
  end;

  MyRecordArray[1].Name:= '';
  MyRecordArray[1].Phone:= '';

You could also sort this list after this type of deletion.  If deleting
needs to be more complicated than this, email me privately, and I try to
help more.

Good Luck,

DeVries Data Systems, Inc. - www.dvdata.com
-=> Please remove NoSpam from address if replying directly <=-



Wed, 18 Jun 1902 08:00:00 GMT  
 Deleting a record....HELP

Quote:

>Hi,

>This may seem like a stupid question.....
>I have an array of records and I know how to add records to that array.
>How would I delete a record from that array?

One solution would be to use collections, then you could use the
Free or AtFree methods.

To remove an item from an array you have to copy all records
down one position and decrement the variable that contains the
number of elements in the array.  You might also want to append
a blank record at the last position.

In the following examples, "Idx" is the subscript of the element
to be deleted.

For i := Idx+1 to LastElement Do
   a[i-1] := a[i];
FillChar(a[LastElement], Sizeof(a[LastElement], 0);
Decrement(LastElement)

OR:

Move(a[Idx+1], a[Idx], Word(LastElement-Idx) * Sizeof(a[1]));
FillChar(a[LastElement], Sizeof(a[LastElement], 0);
Decrement(LastElement)

The word typecast in the "Move" statement forces the expression
to be evaluated as a word rather than an integer.  If the
expression was allowed to be evaluated as an integer it would
cause problems whenever the size of the move was more than 32767
bytes.

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/



Wed, 18 Jun 1902 08:00:00 GMT  
 Deleting a record....HELP


Quote:

>Hi,

>This may seem like a stupid question.....
>I have an array of records and I know how to add records to that array.
>How would I delete a record from that array?

One can either use loop or just move to move the elements. Here is how
to use move. Lets assume that max points to the last element that is
used.

inserting:

move(a[i],a[i+1],sizeof(a[i])*(max-i+1));

Now you can insert store the value at a[i].

As for deleting, just use:

move(a[i+1],a[i],sizeof(a[i])*(max-i));

Now of course after the operations you should adjust max accordingly.
Also in inserting you have to make sure that max is less than the size
of the array. (i.e. that there is at least one unused element at the
end)

I am here assuming that the array is statically allocated or at least
that its size does no change when one inserts and deletes items.If one
wants to change the actual allocation size then the easiest thing is to
allocate the new array, copy the elements from the old and free the old
one.

You were too vague in your question so that I cannot tell more. In
general a few sentences is not enough to describe a problem. You should
use a few paragraphs instead. (And the subject never says it all)

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 Deleting a record....HELP

Quote:

> Hi,

> This may seem like a stupid question.....
> I have an array of records and I know how to add records to that
> array.
> How would I delete a record from that array?

> Thanx!

> Leonard

it's actually a really good question. it depends how you
mean delete though.  if in terms of removing an record
from an external file then thee are various ways..

if this is the case then (and you are using a serial file
access) then you simply copy every record accross
to a new file, check each record as you copy it and
remove the offending record then write the rest of
the record without checking.  when youve finished
simply rename the new "temp" file to the orig.

if its an .idx type file were you have the knowledge
of each record etc then you simply red and write
every record until you know which one you dont
want to copy and leave it, this is faster because
you dont have to check every record so as to
match a fiels or atleast until you reach a
certain letter in the alphabet or something..

if the record you want to blank out is internal,
not from an external file then just set each
record value to a value of nil or nothing...

if you are talking about external files and
want to get into sorting them out alphabetically
etc then its easy enough, use a sorting method,
quicksort, bubble etc..


Quote:
> Hi,

> This may seem like a stupid question.....
> I have an array of records and I know how to add records to that
> array.
> How would I delete a record from that array?

> Thanx!

> Leonard

  algo in Pascal just
mail and ill send it you...

ta,jim



Wed, 18 Jun 1902 08:00:00 GMT  
 Deleting a record....HELP

Quote:

> Hi,

> This may seem like a stupid question.....
> I have an array of records and I know how to add records to that
> array.
> How would I delete a record from that array?

> Thanx!

> Leonard

it's actually a really good question. it depends how you
mean delete though.  if in terms of removing an record
from an external file then thee are various ways..

if this is the case then (and you are using a serial file
access) then you simply copy every record accross
to a new file, check each record as you copy it and
remove the offending record then write the rest of
the record without checking.  when youve finished
simply rename the new "temp" file to the orig.

if its an .idx type file were you have the knowledge
of each record etc then you simply red and write
every record until you know which one you dont
want to copy and leave it, this is faster because
you dont have to check every record so as to
match a fiels or atleast until you reach a
certain letter in the alphabet or something..

if the record you want to blank out is internal,
not from an external file then just set each
record value to a value of nil or nothing...

if you are talking about external files and
want to get into sorting them out alphabetically
etc then its easy enough, use a sorting method,
quicksort, bubble etc..

if you want sort algo in pascal just
mail and ill send it you...

ta,jim



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. DBASE: permanently deleting deleted records

2. adding/deleting records from array of records in .dat file

3. <Help> Record Key Deleted

4. record/key deleted error: help

5. Help:Record/Key Deleted message and Error message Numbers

6. help adding and deleting records from arrays

7. Help needed - deleting a record

8. deleting records -- please help quickly!

9. Need help on "Record/Key deleted"

10. Help: records deleted form paradox tables

11. Sql Server 6, Record/Index Deleted (!?) Help

12. Help : deleting record with MSACCESS 1.0

 

 
Powered by phpBB® Forum Software