ReadLn Procedure

Applies to TestComplete 14.40, last modified on April 22, 2021

The ReadLn procedure reads one line from the file and moves the file pointer to the next line.

Declaration

ReadLn(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 and goes to the next line.

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, which holds the received line.

Remarks

If the ReadLn procedure does not have the Var parameter, it moves the file pointer to the beginning of the next line; if the current line is final, the pointer is placed at the end of the file.

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 a line into the MyVar variable
  ReadLn(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
Read
Write
WriteLn

Highlight search results