0% found this document useful (0 votes)
5 views4 pages

Textfiles Commands

The document provides an overview of text files as a data structure for permanent data storage, highlighting their advantages such as non-volatility and accessibility. It details various commands associated with text files in Delphi, including procedures for reading, writing, and managing file data. Examples of projects that utilize these commands to read and display data from text files are also included.

Uploaded by

ewanchetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Textfiles Commands

The document provides an overview of text files as a data structure for permanent data storage, highlighting their advantages such as non-volatility and accessibility. It details various commands associated with text files in Delphi, including procedures for reading, writing, and managing file data. Examples of projects that utilize these commands to read and display data from text files are also included.

Uploaded by

ewanchetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

GRADE 11

INFORMATION TECHNOLOGY

TEXTFILES

A text file is a data structure that allows for permanent storage of data. These are used to
store information so that easy retrieval and access is achieved without having to manipulate
using simple commands, procedures and functions.

Advantages

 Data is always available at runtime and in the file.


 Data can be saved in primary or in secondary storage
 Data is non- volatile. Ie. Data is not lost when the computer is switched off.
 Data can be used in various applications

COMMANDS ASSOCIATED WITH A TEXTFILE

Assignfile USED TO RELATE THE FILE VARIABLE CREATED IN DELPHI WITH AN


EXTERNAL FILE. THE CONTENTS OF THE EXTERNAL FILE WILL BE
STORED IN THE VARIABLE FILE CREATED.
Procedure AssignFile(fileVariable, externalFileName : string)
Append USED WITH AN EXISTING FILE TO ADD DATA TO THE END OF THE
FILE. HAS ‘WRITE’ONLY ACCESS. THE FILE POINTERR WILL BE
POSITIONED AFTER THE LAST LINE IN THE TEXTFILE.
Procedure Append(fileVariable)
CloseFile USED TO CLOSE THE ASSOCIATION BETWEEN THE FILE VARIABLE
AND THE EXTERNAL FILE
Procedure closefile(fileVariable)
Eof (End of file) RETURNS A BOOLEAN VALUE TRUE OR FALSE. IF THE
FILE IS AT THE END , IT WILL RETURN TRUE OTHERWISE IT WILL
RETURN FALSE
Function Eof(fileVariable): Boolean
FileExists USED TO CHECK IF THE FILE EXISTS OR NOT. RETURNS A BOOLEAN
VALUE IF THE FILE EXISTS; OR FALSE IF THE FILE DOES NOT EXIST.
Function FileExists(filename: string): Boolean
Readln READS A LINE OF TEXT FROM A FILE DEPENDING ON WHERE THE
POINTER IS POSITIONED.
Procedure Readln(fileVariable, text: string);
Rewrite USED TO CREATE A NEW FILE. IF THERE IS ANOTHER FILE IN THE
SAME DIRECTORY WITH THE SAME FILE NAME, THAT FILE WILL BE
DELETED. WILL BE OPENED FOR ‘WRITE’ONLY ACCESS. THE FILE
POINTER IS POSITIONED AT THE BEGINNING OF THE FILE
Procedure Rewrite(fileVariable)
Reset USED TO READ FROM AN EXISTING FILE. THE FILE POINTER IS
POSITIONED AT THE BEGINNING OF THE FILE FOR READING
PURPOSES.
Procedure Reset(fileVariable)
Write WRITES DATA TO A FILE WHICH THE CURSOR REMAINS THE ON
THE SAME LINE.
Procedure Write(fileVariable, text :string)
Writeln WRITES DATA TO A FILE AFTER WHICH THE CURSOR MOVES
ONTO THE NEXT LINE
Procedure Writeln(fileVariable, text: string)
Nb. ALWAYS SAVE THE TEXTFILE AND THE DELPHI FILES IN THE SAME FOLDER.

READING DATA FROM A TEXTFILE

THE COMMANDS THAT ARE GENERALLY USED ARE ASSIGNFILE, FILEEXISTS, RESET, EOF,
READLN AND CLOSEFILE.

EXAMPLE

A TEXTFILE CALLED names.txt IS CREATED. THE FOLLOWING NAMES ARE STORED IN


THE TEXTFILE.

CREATE A PROJECR CALLED READNAMES THAT USES A BUTTON TO READ THE


CONTENTS OF THE TEXTFILE AND DISPLAY THE NAMES VERTICALLY IN A BOX.
READ NAMES FROM FILE
EXAMPLE 2

A TEXTFILE CALLED data.txt HAS FOLLOWING DATA

Sipho Khumalo#Male#1998-01-02

Sahil Phagoo#Male#1996-11-14

Thando Tshabalala#Male#1997-02-01

Vilashni Mottian#Female#1996-03-12

Tom Peters#male#1993#11-12

Lerusha Naidoo# Female#1992-08-24

CREATE A PROJECT CALLED READDATA. CREATE THE FRONT END AS GIVEN BELOW

You might also like