Delphi record type of file

Source: Internet
Author: User
Tags file type file

I. Record file type file:

1 can be roughly understood as a database, such as the local QQ program in some account information set (account number, password, last logon time, etc.) recorded in the. dat file.

2 record file type file vs database

Same point: All can be used to record data

Difference: Record file type files are similar to Notepad record data, resulting in the deletion of data is not as convenient as the database.

3 The Delphi record type document definition

First step:

Define a set of records

Type

Myfile= Record

NAME:STRING[20]; You must specify the size of the string in the recordset

SEX:STRING[10]; Ditto

Age:integer;

End End

Part II:

Declares a recordset file, while declaring a recordset

Myselffile:file of MyFile; Affirm recordset file

Myselfinfo:myfile; DECLARE recordset

Part III:

Assigning values to recordsets and recordset files

Assigning values to recordsets

Myselfinfo.name: = Edit1.text;

Myselfinfo.sex: = Edit2.text;

Myselfinfo.age: = Strtoint (Edit3.text);

Assign values to the recordset file below

If Savedialog1.execute Then

Begin

AssignFile (Myselffile, savedialog1.filename); Hook a recordset to a disk file,

Write this sentence immediately write CloseFile (myselffile);

If FileExists (savedialog1.filename) then//determine if the file exists

Reset (Myselffile)//exists to open as read-only (Rewrite), delete the original file, and then create a new file

else Rewrite (myselffile); Does not exist is opened in a write-only manner;

In both ways, the file (myselffile) pointer points to the 0-bit child of the file's contents

Seek (Myselffile, FileSize (myselffile)); This sentence points the pointer to the end of the file.

Write (Myselffile, myselfinfo); Writes a recordset to a file. Reads in read (Myselffile, myselfinfo);

CloseFile (Myselffile); Turn off associated with the disk, and AssignFile corresponds

End

Fourth Step: Finally

Suppose you write to the following group of records

Control: Edit1.text Edit2.text Edit2.text

Information: Zhang So-and-so man 21

Zhou So-and-So woman 21

The XXX male 21

Meng So-and-So woman 21

Zheng So-and-So man 21

Wang So-and-so man 21

Text opened after the contents of the file (note:& is garbled)

Zhang So-and-so male & Zhou xxx female & XXX male & Meng xxx & Zheng So-and-so man & Wang So-and-so Man &

Note: Only the read (Myselffile, myselfinfo) data can be used in the software for normal reading.

Summary: A record set is like a class in Java. Writing is also a bit like java. Learn Delphi, nothing can edify

SOURCE http://7071976.blog.51cto.com/7061976/1208387

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.