TDosStream.Seek

Set file position.

Declaration

Source position: objects.pp line 352

default 
  procedure Seek(Pos: LongInt);  Virtual;

Description

If the stream's status is stOK, then Seek sets the file position to Pos. Pos is a zero-based offset, counted from the beginning of the file.

Errors

In case an error occurs, the stream's status is set to stSeekError, and the OS error code is stored in ErrorInfo.

See also

Name Description
TStream.GetPos Return current position in the stream
TStream.Seek Set stream position.

Example

Program ex17;
{ Program to demonstrate the TStream.Seek method }
Uses Objects;
Var L : String;
    Marker : Word;
    P : PString;
    S : PDosStream;
begin
  L:='Some constant string';
  { Buffer size of 100 }
  S:=New(PDosStream,Init('test.dat',stcreate));
  Writeln ('Writing "',L,'" to stream.');
  S^.WriteStr(@L);
  Marker:=S^.GetPos;
  Writeln ('Set marker at ',Marker);
  L:='Some other constant String';
  Writeln ('Writing "',L,'" to stream.');
  S^.WriteStr(@L);
  S^.Close;
  S^.Open (stOpenRead);
  Writeln ('Size of stream is : ',S^.GetSize);
  Writeln ('Seeking to marker');
  S^.Seek(Marker);
  P:=S^.ReadStr;
  L:=P^;
  DisposeStr(P);
  Writeln ('Read "',L,'" from stream.');
  S^.Close;
  Dispose (S,Done);
end.

results matching ""

    No results matching ""