•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 391,592 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,717 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 4361 | Replies: 2
![]() |
•
•
Join Date: Apr 2005
Posts: 10
Reputation:
Rep Power: 4
Solved Threads: 0
Can anyone tell me the format for reading information into a program and if I want to save information out of the prgram into a txt file.
I understand it to be
Assign (file name, path)
reset (filename)
close (file name)
and to write information out
assign (filename, path);
rewrite(filename, with all the information)
close (filename)
Which brings up another question: Is it possible to read the txt file line by line and then save it out to another txt file line by line or must it be done as a entir file?
I understand it to be
Assign (file name, path)
reset (filename)
close (file name)
and to write information out
assign (filename, path);
rewrite(filename, with all the information)
close (filename)
Which brings up another question: Is it possible to read the txt file line by line and then save it out to another txt file line by line or must it be done as a entir file?
•
•
Join Date: Jan 2005
Location: Georgia, USA
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
File I/O line-by-line (for text files) is fairly simple.
Assign associates an external filename with a file variable. This is the first step in file I/O. After the Assign, all references to the file are made through the file variable.
Reset opens a file for reading, preserving the contents and placing the file position at the beginning.
Rewrite opens a file for writing, destroying the contents and placing the file position at the beginning.
For Reset and Rewrite: If the file is an untyped file (i.e. F : file ), an optional record size parameter can be passed to the call (i.e. Reset( F, 256 )). Default record size is 128.
Append is used to open a text file, placing the file position at the end, to allow for the addition of text to the file.
File I/O with typed files is just about the same. Declare a file of a structured type (i.e. F : file of CustRec), then do a Reset. To get to record number N, call Seek( F, N ), where the first record in the file is record 0. In the case of file I/O on untyped files, Seek( F, N ) will seek N records into the file based on the filesize passed when the file was opened.
Be aware that some of this information may be specific to Delphi, but I believe it to be applicable to modern "generic" Pascal compilers. (For instance, Delphi now uses AssignFile to replace Assign, as Assign is now a method call in objects).
Assign associates an external filename with a file variable. This is the first step in file I/O. After the Assign, all references to the file are made through the file variable.
Reset opens a file for reading, preserving the contents and placing the file position at the beginning.
Rewrite opens a file for writing, destroying the contents and placing the file position at the beginning.
For Reset and Rewrite: If the file is an untyped file (i.e. F : file ), an optional record size parameter can be passed to the call (i.e. Reset( F, 256 )). Default record size is 128.
Append is used to open a text file, placing the file position at the end, to allow for the addition of text to the file.
File I/O with typed files is just about the same. Declare a file of a structured type (i.e. F : file of CustRec), then do a Reset. To get to record number N, call Seek( F, N ), where the first record in the file is record 0. In the case of file I/O on untyped files, Seek( F, N ) will seek N records into the file based on the filesize passed when the file was opened.
Be aware that some of this information may be specific to Delphi, but I believe it to be applicable to modern "generic" Pascal compilers. (For instance, Delphi now uses AssignFile to replace Assign, as Assign is now a method call in objects).
procedure CopyFile;
var
F1 : text;
F2 : text;
FN1 : string;
FN2 : string;
begin
FN1 := 'infile.txt';
FN2 := 'outfile.txt';
assign( F1, FN1 );
reset( F1 ); { open file for reading }
assign( F2, FN2 );
rewrite( F2 ); { open file for writing, destroying contents, if any }
while not EOF( F1 ) do
begin
readln( F1 );
{ file manipulation goes here }
writeln( F2 );
end;
close( F1 );
close( F2 );
end;![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
Similar Threads
- TXT Plays like a Music File? (JavaScript / DHTML / AJAX)
- vb6/common dialog/access db (Visual Basic 4 / 5 / 6)
- iserror.txt popping up in random spots (Viruses, Spyware and other Nasties)
- creating Contact form to email and txt file (PHP)
- Need some help plz; ima newb (not sure how to catagorize this particular prob) (C++)
- This could be an easy fix for bridge.dll? (Viruses, Spyware and other Nasties)
- How to find files to transfer to jump drive (Windows 9x / Me)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Delphi Help
- Next Thread: Screen Commands in Pascal


Linear Mode