|
Positioning File
|
|
|
File position specifies offset in file to read or write data at. It is always specified in bytes (regardless of type of data accessed) and can have values within range
0 (beginning of file) to file length (end of file; one byte beyond last byte in file). On usual file activity, its position is adjusted automatically whenever data is read or written;
on each Get and Put operation it is moved forward by the number of bytes actually read or written.
Developers have several ways for changing file position to access data at.
The easiest is to specify position as an argument in Get and Put; all of these methods have such parameter which is used to automatically
position file before accessing data. If you wish to use current position just specify value of -1, which is also default; see Reading and Writing Data
for more information on reading and writing data.
Automatic positioning is not always the best solution and therefore manual positioning is supported. To set absolute position use
SetPosition method which allows changing position to be located anywhere in the file or at the end of file. On the contrary
Skip methods allows relative positioning by moving file position forwards or backwards by specified number of bytes.
In both cases unsaved data present in internal buffer is flushed to the file prior to changing its position.
To retrieve current file position use GetPosition method.
Please note that file position set or returned with IXFile methods specifies offset in file for accessing data with IXFile methods only.
Physical position of the file pointer can be different (and almost always is) and is changed internally only when needed.
Examples
C++
int main(int, char**)
{
IFile ixf;
long lng1, lng2, lng3;
long position;
ixf.SetLicenseKey("YOURLICENSEKEY");
ixf.Initialize();
ixf.Open("test.bin");
ixf.GetLong(&lng1, 1, 100);
ixf.PutLong(&lng1, 1);
position = ixf.GetPosition();
ixf.SetPosition(100);
ixf.GetLong(&lng2, 1);
ixf.SetPosition(position);
ixf.Skip(-4);
ixf.GetLong(&lng3, 1);
.
.
.
return(0);
}
BASIC
Sub Main()
Dim ixf As IXFile
Dim lng1 As Long, lng2 As Long, lng3 As Long
Dim position As Long
Set ixf = New IXFile
ixf.SetLicenseKey "YOURLICENSEKEY"
ixf.Initialize
ixf.Open "test.bin"
ixf.GetLong lng1, 1, 100
ixf.PutLong lng1
position = ixf.GetPosition()
ixf.SetPosition 100
ixf.GetLong lng2
ixf.SetPosition position
ixf.Skip -4
ixf.GetLong lng3
.
.
.
End Sub
See Also
SetPosition,
GetPosition,
Skip,
Reading and Writing Data