Cursor Property

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

Description

Use the Cursor property to read the current position or to set a new position within a binary file.

Declaration

aqBinaryFileObj.Cursor

Read-Write Property Integer
aqBinaryFileObj An expression, variable or parameter that specifies a reference to an aqBinaryFile object

Applies To

The property is applied to the following object:

Property Value

A zero-based integer number that specifies a position in a file.

Remarks

After the file is opened, the Cursor property points to the end or to the beginning of the file. If the file is open for reading, Cursor points to the beginning of the file. If the file is open for writing or appending, Cursor points to the end of the file (the cursor is positioned right after the last byte of the file’s content).

Example

The code below demonstrates how you can use the Cursor property to specify the byte to be read from a file. For example, you may want to read specific bytes from some file. Let's assume that we have the FileName.txt file with the following data: {Demo file}. Now we want to read the eleventh byte of this file (it is the } symbol) and post this byte to the test log. Note that the cursor position in this case is 10, as the property value is zero-based.

JavaScript, JScript

function SpecifyingCursorLocation()
{
  Path = "C:\\MyFiles\\FileName.txt";

  // Opens the file for reading
  myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead);

  // Specifies the cursor position
  myFile.Cursor = 10;
  
  // Reads the byte and posts its value to the test log
  Log.Message(myFile.ReadByte());
}

/*
This routine produces the following output:
125
*/

Python

def SpecifyingCursorLocation():
  Path = "C:\\MyFiles\\FileName.txt"
  # Opens the file for reading 
  myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
  # Specifies the cursor position
  myFile.Cursor = 10
  # Reads the byte and posts its value to the test log
  Log.Message(myFile.ReadByte())

# This routine produces the following output:
# 125

VBScript

Sub SpecifyingCursorLocation
Dim myFile
  Path = "C:\MyFiles\FileName.txt"

  ' Opens the file for reading
  Set myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)

  ' Specifies the cursor position
  myFile.Cursor = 10
  
  ' Reads the byte and posts its value to the test log
  Log.Message(myFile.ReadByte())
End Sub

' This routine produces the following output:
' 125

DelphiScript

procedure SpecifyingCursorLocation;
var Path, myFile;
begin
  Path := 'C:\MyFiles\FileName.txt';

  // Opens the file for reading
  myFile := aqFile.OpenBinaryFile(Path, aqFile.faRead);

  // Specifies the cursor position
  myFile.Cursor := 10;
  
  // Reads the byte and posts its value to the test log
  Log.Message(myFile.ReadByte());
end;

{
This routine produces the following output:
125
}

C++Script, C#Script

function SpecifyingCursorLocation()
{
  Path = "C:\\MyFiles\\FileName.txt";

  // Opens the file for reading
  myFile = aqFile["OpenBinaryFile"](Path, aqFile.faRead);

  // Specifies the cursor position
  myFile["Cursor"] = 10;
  
  // Reads the byte and posts its value to the test log
  Log["Message"]( myFile["ReadByte"]() );
}

/*
This routine produces the following output:
125
*/

See Also

Working With Files From Scripts
OpenBinaryFile Method

Highlight search results