[Gambas-user] READ-Event on #File.in ???

Benoit Minisini gambas at ...1...
Thu Jul 10 21:32:27 CEST 2008


On jeudi 10 juillet 2008, gambas at ...1938... wrote:
> > If you declare a STATIC PUBLIC SUB named Application_Read() in your
> > startup class, then you will get what you want: the File.In stream is
> > watched, and the Application_Read() function is called as soon as there
> > is something to read on the standard input.
>
> Hi Benoit,
>
> sorry, I couldn't find any further docu regarding
> Apllication_READ(). ..nothing via "F1", nothing in the wiki. It's seem's 
> to be one of the hidden secrets! ;-)

The Application_Read global event handler is documented in the Application 
class documentation page. But you won't get more information than I wrote 
you.

> How do I get access on the data?? How must Application_Read() should look
> like???
> I'm pretty new to this OO-Stuff....so I depend on docu or examples!
> ....sorry!!
>
> Greetz
> Stevie
>

You must understand how watched file objects work. A file is an object of 
class "File" that will raise events when it is watched: the Read event when 
there is something to read on that File object, the Write event when there is 
something to write. 

As the standard input is a special case, I defined the "Application_Read" 
static public method as the global "Read" event handler for the standard 
input, provided that this method is defined in the startup class.

Here is a little example that write on a file the standard input. But you must 
upgrade to revision #1445 to be sure that it will work!

' Gambas module

PRIVATE $hOut AS File

PUBLIC SUB Main()
  $hOut = OPEN "~/output.txt" FOR WRITE CREATE
END

PUBLIC SUB Application_Read()
  DIM sData AS String
  READ sData, -256
  IF Len(sData) = 0 THEN ' Means that the input was closed
    CLOSE #File.In
    CLOSE #$hOut
  ELSE
    WRITE #$hOut, sData, Len(sData)
  ENDIF
END

Regards,

-- 
Benoit Minisini




More information about the User mailing list