Read Procedure

Applies to TestComplete 15.47, last modified on January 20, 2023

The Read procedure reads one line from the specified file.

Declaration

Read(FileVarVar) Parameters
FileVar [in] Required Variant
Var [in] Required String
Result     None  

Description

Reads one line from the file, which is associated with the file variable by calling the AssignFile procedure, then assigns this line to the specified variable.

Parameters

The procedure has the following parameters:

FileVar

Specifies the file variable, which is associated with the desired file by calling the AssignFile procedure.

Var

Specifies the variable that holds the received line.

Remarks

The procedure below reads all characters up to the end-of-line marker, or up to the end of the file (see EOF). It does not skip to the next line, and every subsequent call to Read returns an empty string. If you want to read a set of string values, use ReadLn.

Example

Since TestComplete works with variant variables, the received string can be converted to any other data type. The following example demonstrates how you can work with data received from the file.

DelphiScript

var
  FileVar: OleVariant;
  MyVar: OleVariant;
begin
  // Opens a file
  AssignFile(FileVar, 'C:\My File.txt');
  Reset(FileVar);
  
  // Reads data from the file into the MyVar variable
  Read(FileVar, MyVar);
  // Outputs the data to the test log
  Log.Message(MyVar);
  
  // Closes the file
  CloseFile(FileVar);
end;

See Also

DelphiScript - List of Supported Routines and Variables
AssignFile
EOF
ReadLn
Write
WriteLn

Highlight search results