Board index » delphi » Read Write Access on a file

Read Write Access on a file

I am opening untyped files in pascal that are in excess of 10Mbytes and
at the moment I am copying them to a temp file rewriting the original
file and the copying them back (SLOW even with blockread). what I need
is to know how to open a file and have read/write access to it (like
basic [yuck])
--
______________________________
Adam Anderson. Comms Tech.
Email must contain Adam97 in
Subject or it will be deleted.

 

Re:Read Write Access on a file


Quote
Adam Anderson wrote:
> I am opening untyped files in pascal that are in excess of 10Mbytes and
> at the moment I am copying them to a temp file rewriting the original
> file and the copying them back (SLOW even with blockread). what I need
> is to know how to open a file and have read/write access to it (like
> basic [yuck])

For untyped or typed files, make sure filemode is set to 2 (read/write,
this is the default value), then use reset() to open the file.  You can
seek and read or write anywhere in the file.  However, it's generally a
good idea to have a flush function to make sure data gets written
properly to the file.

Quote
> --
> ______________________________
> Adam Anderson. Comms Tech.
> Email must contain Adam97 in
> Subject or it will be deleted.

--
Scott Earnest        | We now return you to our regularly |
set...@ix.netcom.com | scheduled chaos and mayhem. . . .  |

Re:Read Write Access on a file


Quote

I am opening untyped files in pascal that are in excess of 10Mbytes and
at the moment I am copying them to a temp file rewriting the original
file and the copying them back >>

How about opening it as a

FILE OF CHAR;

Rick
Rick H...@aol.com

Re:Read Write Access on a file


Quote
Adam Anderson <not...@usa.net> wrote:
>I am opening untyped files in pascal that are in excess of 10Mbytes and
>at the moment I am copying them to a temp file rewriting the original
>file and the copying them back (SLOW even with blockread). what I need
>is to know how to open a file and have read/write access to it (like
>basic [yuck])

There doesn't seem to be many business related tasks discussed here,
so the following might be a waste of time. Even so, concerns for the
client's data does merit a little attention from time to time.

If you can afford to modify the file in place, then follow Scott
Earnest's suggestion.  If you can't afford to have a partially
modified file, then you need some scheme to recover should the task
be interrupted.  In this case copy the file to a temp name (old
fashion convention is filename.$$$ to denote a working file).  After
the session is complete, delete filename.BAK, rename existing file
to filename.BAK, then rename filename.$$$ to original file.  In case
the BAK file doesn't exist, turn error checking off and clear any
error when you delete it.  

This technique insures there is always a valid copy of the data
file.  If you don't want to save the previous version, you can
delete the final BAK file once all the renaming is complete.  If the
$$$ file exists, then the user can fall back to the original file if
it exists, otherwise restore the BAK file.  If $$$ does not exist,
then the original file name contains the latest copy, and BAK file
(if it exists) contains the previous version.

The overhead of copying a 10meg file through a 60k buffer is a minor
price to pay when the alternative of losing everything is taken into
consideration.  Even if the files are backed up it is quicker, and
therefore cheaper, to recover from a BAK file than having to restore
from a backup tape.  Usually when a backup is restored it still
requires additional processing to bring it into sync with the rest
of the system.

    ...red

Re:Read Write Access on a file


On 28 Mar 1997 03:34:42 GMT, rickh...@aol.com (Rick Hall) wrote:

Quote

>I am opening untyped files in pascal that are in excess of 10Mbytes and
>at the moment I am copying them to a temp file rewriting the original
>file and the copying them back >>

>How about opening it as a

>FILE OF CHAR;

>Rick
>Rick H...@aol.com

How about opening it as a file of type TEXT? That IS a file of CHAR!

Frank Wood
wood...@dircon.co.uk

Re:Read Write Access on a file


Quote
Frank Wood wrote:

> On 28 Mar 1997 03:34:42 GMT, rickh...@aol.com (Rick Hall) wrote:

> >I am opening untyped files in pascal that are in excess of 10Mbytes and
> >at the moment I am copying them to a temp file rewriting the original
> >file and the copying them back >>

> >How about opening it as a

> >FILE OF CHAR;

> >Rick
> >Rick H...@aol.com

> How about opening it as a file of type TEXT. That IS a file of CHAR!

Because if you open a file as type text and there is an end-of-file
marker in the middle of it, you can't read past it.  As well, text
files can only be opened with Reset for reading or Rewrite/Append
for writing:  if you need both read and write access on the same
file you are screwed.  Needing random access in the file is
another reason not to use text files.

- Show quoted text -

Quote
> Frank Wood
> wood...@dircon.co.uk

Re:Read Write Access on a file


On 28 Mar 1997 03:34:42 GMT, rickh...@aol.com (Rick Hall) wrote:

Quote

>I am opening untyped files in pascal that are in excess of 10Mbytes and
>at the moment I am copying them to a temp file rewriting the original
>file and the copying them back >>

>How about opening it as a

>FILE OF CHAR;

>Rick
>Rick H...@aol.com

How about opening it as a file of type TEXT. That IS a file of CHAR!

Frank Wood
wood...@dircon.co.uk

Re:Read Write Access on a file


Quote

How about opening it as a file of type TEXT? That IS a file of CHAR!
<<

Not exactly, TEXT is a specialized descendant of FILE OF CHAR

What he wants is FILE OF <whatever record this file is composed of>

So CHAR! He can SEEK at will. Without my manuals at hand, I'm not sure you
can SEEK in a TEXT file

Rick
Rick H...@aol.com

Re:Read Write Access on a file


Quote
> How about opening it as a file of type TEXT? That IS a file of CHAR!
> Not exactly, TEXT is a specialized descendant of FILE OF CHAR

> What he wants is FILE OF <whatever record this file is composed of>

> So CHAR! He can SEEK at will. Without my manuals at hand, I'm not sure > you can SEEK in a TEXT file

   You can't (do Seek on Text files) - only read(ln) or write(ln) (only
sequential access).  Thus, the subject cannot be done on Text files
(read/write access), and opening/processing the data as some other file
type is the only way to achieve it.

Re:Read Write Access on a file


On Mon, 07 Apr 1997 23:31:29 -0400, Rob Stow <s...@sask.usask.ca>
wrote:

Quote
>Frank Wood wrote:

>> On 28 Mar 1997 03:34:42 GMT, rickh...@aol.com (Rick Hall) wrote:

>> >I am opening untyped files in pascal that are in excess of 10Mbytes and
>> >at the moment I am copying them to a temp file rewriting the original
>> >file and the copying them back....

I've not seen the early part of this thread, but I wonder from what I
have seen if opening the files as

file of byte

would give the user the ability to do what he wants to?

chr and ord give you ways to turn bytes into characters and vice
versa.

http://kestrel.arunet.co.uk/tkboyd/offers.htm
Freeware, shareware for IBM type pcs. Ideas for parents, teachers

Other Threads