Hello Jeremy,
Mostly I think the answer to your question depends on how you use the
flat file. If you use it as a random access file ( I.e. read record #n at
n*length(record) ) then the best way of deleting one record would be to
implement your records as a linked list. Then, to delete a record, all
you'd have to do is change two pointers in the file. ( if you don't know
what the EFF I am talking about, let me know and I will explain ).
You would end up with dead wood in the file, but then you could do
a restructuring as a regular (weekly?) management feature.
Alternatively, if you do sequential access, I feel that it would still be
faster to read all records into a dynamic array, delete the record in
question from there, and then write the dynamic array back to file.
cheers, -Peter
> HI all.
>
> I was wondering if there is a way to do the following better, i.e. a
> procedure/fuction I can use.
>
> I have a flatfile DB that I save record structures into.
> From time to time, I want to delete a record from the file.
> I can EDIT the record ok, but to delete a record I do the following :-
>
> Loop thru the records putting the records that dont match the name I am
> looing for into another flatfile DB, and when the name I am want to delete
> is found I the just dont add that record to the new DB, then when its
> finished, I delete the DB, rename the second one back to the original one,
> i.e. from db.tmp to db.dat etc. But I wonder if this IS the best way. It
> does delete duplicate names too, but thats my fault..
>
> Can anyone suggest a better way ?
>
> Cheers, Jeremy Coulter
>
>
>
> Jeremy Coulter (Manager)
> Visual Software Solutions
> Christchurch, New Zealand
> PH 03-3521595
> FAX 03-3521596
> MOBILE 021-2533214
> www.vss.co.nz
>
> ---------------------------------------------------------------------------
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"