Solved

truncate from down to up

Posted on 2003-12-02
9
205 Views
Last Modified: 2012-05-04
how i can create function, which delete from file line which is first

whis delete line from last

  AssignFile(F, DBname);
  Reset(F);
  Seek(F, FileSize(F)-1);
  Truncate(F);
  CloseFile(F);

I need the same but from first record to last
0
Comment
Question by:bulbul2
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 1

Accepted Solution

by:
roknjohn earned 20 total points
ID: 9859470
it takes longer because you have to move each record up.  One way is:

  AssignFile(F, DBname);
  Reset(F);
  for i := 0 to FileSize(f)-2 do begin
    Seek(F, i+1);
    Read(F,X);
    Seek(F, i);
    Write(F,X);
  end;
  Seek(F, FileSize(F)-1);
  Truncate(F);
  CloseFile(F);

If the file is small, you can just read the whole file in, then write it out again (less the first record, of course).
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9859486
copy the last record over the first (or any before last) record,
and truncate the file as above

meikl ;-)
0
 
LVL 1

Expert Comment

by:roknjohn
ID: 9859540
>>copy the last record over the first

That would work, but it wouldn't preserve the record order of the file, which I assumed was important.  

I like your thinking, though. :-)
0
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!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9859793
:-))
usual i do so on sequential files,
because its the fast solution,
but as you stated, it will dissort the recordorder

take also a look to this q
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20147576.html

meikl ;-)
0
 
LVL 5

Expert Comment

by:delphized
ID: 9864809
To have best performance you should act in this way: put a flag in your rows and virtually delete a row with marking this flag.
when you want to phisically delete the records marked (shrink the file) you make a new file and copy all the records not marked to it.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9864824
0
 
LVL 5

Expert Comment

by:delphized
ID: 9896815
And so...?..
0
 
LVL 2

Expert Comment

by:-Karamja-
ID: 12382178
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: roknjohn

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Karamja (Alan)
EE Cleanup Volunteer
0

Featured Post

Technology Partners: 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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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