Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-12

TIOStream and .Position

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Žilvinas Ledas

Hello all,

is this intended behavior or it is a bug that iostream.Position always returns -1?
In iostream unit I see that there is

<...>
  TIOStream = class(THandleStream)
  private
    FType : longint;
    FPos : Int64;
<...>

but if I use code like:

<...>
var
  iostream: TIOStream;
begin
  iostream := TIOStream.Create(iosInput);
  iostream.Position; // = -1
  iostream.Read(bufferin, 10);
  iostream.Position; // = -1
end;
<...>

I don't get the right Position value...

Regards,
Zilvinas Ledas

Jonas Maebe
to Žilvinas Ledas
Žilvinas Ledas wrote
is this intended behavior or it is a bug that iostream.Position always returns -1?

Are you reading from standard input or so? In that case it's logical that the position is always -1, since you can't seek standard input (in theory it's infinitely large).

Jonas

Žilvinas Ledas
to Jonas Maebe

Yes, I am. But I thought that it is not that logical after I found function: ---
FPos: Int64;
---
and
---
function TIOStream.Seek(Offset: Longint; Origin: Word): Longint; <...>
{ Try to fake seek by reading and discarding }
<...>
---
Either way, I have modified mine iostream code to return currently available FPos: Int64 and now I can use Position to know how many bytes were read from the time I have created input stream. It is usefull as I am using generic TStream which in my app can be TFileStream, TStringStream or TIOStream and now I can use the same stream.Position with valid result (as long as I do not seek).

If it is intended behaviour to return -1 it is ok by me ;) I just wanted to check if it wasn't a bug.

Regards,
Zilvinas Ledas

Jonas Maebe wrote 14 lines
On 05 Dec 2009, at 21:42, Žilvinas Ledas wrote: > is this intended behavior or it is a bug that iostream.Position always returns -1? > Are you reading from standard input or so? In that case it's logical that the position is always -1, since you can't seek standard input (in theory it's infinitely large). Jonas_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal