Delphi read-Write text file (full function comparison)

Source: Internet
Author: User

Requires two buttons and two RichEdit controls, with a default name.

Procedure Tform1.button1click (Sender:tobject); Write a file

var wtext:textfile;
Begin
AssignFile (Wtext, ' ip.txt ');
Rewrite (Wtext);//Create a file or use reset to open the file
Writeln (Wtext, Richedit1.text);
CloseFile (Wtext);
End

Procedure Tform1.button2click (Sender:tobject); Read the file
var rtext:textfile;
tmp:string;
Begin
Richedit2. clear;//clear the original content
AssignFile (Rtext, ' ip.txt ');
Reset (Rtext);
While not EOF (Rtext) does
Begin
READLN (RTEXT,TMP);
Richedit2. Lines.add (TMP);
End
CloseFile (Rtext);
End

Related knowledge Content:

Before you make any processing of a text file, you first open the text file. Declaring variables: You can refer to a text file by using this variable.
Opening a file takes two steps: First, AssignFile (), which associates a file variable with a file. For example: At this point, you can take the second step: Open the file. There are three ways to open a file: Use the r e W r i t E () procedure to create and open a file, and for an existing file, this action will overwrite the file, open a file read-only using the R e S e t () procedure, and append text to the existing file using the Append () procedure.
Note Reset () opens the type file and the untyped file in a read-write manner. You can use CloseFile () to close an open file.

This article was reproduced in: http://blog.csdn.net/biku/article/details/1515479

The following are the functions of the various calls:

Opening and closing of files:
AssignFile: To correlate an external file name with a variable
Reset: Open a file that exists
Rewrite: Create and open a new file (or overwrite the original file)
Append: Open a file as added (only for text files)
CloseFile: Close an open file
FileOpen: Opens a specific file and returns a file handle
Filecreate: Creates a file with a given file name and returns a file handle
FileClose: Closing a file with a specific handle
The back three files are intended for internal use by the system and are often used in the programming of file replication. The objects they manipulate are file handles rather than file variables.

File Location:
Seek: Moves the current position of the file to the specified section
Filepos: Returns the current location of the file
Eoln: Return line End Flag
EOF: Return end of File flag
FileSeek: Changing the position of the current file pointer

Http://www.cnblogs.com/taomaomao/archive/2012/03/14/2395664.html

Delphi read-Write text file (full function comparison)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.