Files 

Structured Files

You can use standard Pascal file processes, which are:

Routine Purpose Example
Append Open an existing file for appending
AssignFile or Assign Assign filename to file or TextFile  assignfile(c_file, 'n:\cons.dat');
BlockRead Read data from a file
BlockWrite Write data to a file
CloseFile or Close Close an open file closefile(c_file);
Eof True if end of file while not eof (c_file) do
Erase Delete a file
File File type for structured data c_file:file of Tconsignment;
FileMode 0=read only, 2=read/write, 1=write only
FilePos Return current file position
FileSize Return size of file in records
Read Read formatted data from file read(c_file, c_record);
Rename Rename a file
Reset Open file for reading reset(c_file);
Rewrite Open file for writing, erasing previous data rewrite(c_file);
Seek Change file position seek(c_file, filesize(c_file));
Write Write formatted data write(c_file, c_record);

Sequential Files

Details - Creating, Updating, Deleting, Amending

Merging Files

Further examples of sequential file processing can be found in the Projects section (PostQuickParcels and HospitalEquipment).

Details of file creation inside a StringGrid can be found in the section on the StringGrid.

Direct Access Files

 

Text Files

The standard routines for text files are: 

Routine Purpose Example
Readln Read line from text file readln(actfile, textline);
Text or TextFile File type for plain text file actfile: textfile;
Writeln Write a line of text

The following code declares a text file and then reads it line by line into a memo control:

var
 actfile: textfile;
 actname, actfilename, textline: string;

begin
 memo1.Clear;
 assignfile(actfile, actfilename);
 reset(actfile);
 while not eof (actfile) do
  begin
   readln(actfile, textline);
   memo1.Lines.Add(textline);
  end;
end;

 

Back to Delphi Menu