Solved

truncate from down to up

Posted on 2003-12-02
9
201 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
:-))
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:delphized
Comment Utility
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
Comment Utility
0
 
LVL 5

Expert Comment

by:delphized
Comment Utility
And so...?..
0
 
LVL 2

Expert Comment

by:-Karamja-
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now