Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

truncate from down to up

Posted on 2003-12-02
9
Medium Priority
?
208 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 80 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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