In our previous episode, Michael Van Canneyt said: > > Is there a way to ask whether the input stream is not empty, without > > waiting and without using threads/processes? > > And, in addition, is there an OS-independent way (linux, windows)? > > > > something like: > > var > > inputStream: THandleStream; > > aByte: Byte; > > begin > > InputStream := THandleStream.Create(StdInputHandle); > > try > > while true do > > begin > > {$I-} > > aByte := InputStream.ReadByte; > > DoSomethingWithByte(aByte); > > result := true; > > end; > > except > > On E: EStreamError do result := false; > > end; > > //This code here is never executed > > ThereIsNothingInInputStream_DoDefault; > > end; > > You must use fpSelect() or Poll on the handle on linux/unix. > On windows, you'll need to WaitForObject() or so on the file handle.
Be careful on streams that might have buffers though. Then you first need to check if there are still bytes in the buffer. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal