Solved

truncate from down to up

Posted on 2003-12-02
9
203 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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