Solved

truncate from down to up

Posted on 2003-12-02
9
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

623 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