[Gambas-user] ncurses howto

Tobias Boege taboege at gmail.com
Mon May 27 20:52:39 CEST 2019


On Mon, 27 May 2019, Demosthenes Koptsis wrote:
> Hello,
> 
> i try ncurces with gambas3 and i have some difficulties.
> 
> i created a console application and i have the following code:
> 
> ' Gambas module file
> 
> Public Sub Main()
>   ' Display a message window
>   Dim hMessage As New Window(True, 0, 0, 800, 600)
>   hMessage.Border = 1
>   hMessage.Background = Color.Blue
>   hMessage.Foreground = Color.White
>   hMessage.Print("Surprise!")
>   hMessage.Show()
>   Wait 10
> 
> End
> 
> if i dont write WAIT 10 seconds i get a black screen.
> 
> if i write WAIT 10 seconds i get the desired ncurses screen visible for 10
> secs.
> 
> How i can have the ncurses screen always visible?
> 

hMessage is a local variable. As soon as you leave the scope of the
Main sub, it goes out of scope and gets destroyed (because for some
reason being `Show`n does not automatically increase the reference
count of a Window in gb.ncurses). Put it into a class-global variable
instead:

  Private $hMessage As Window

  Public Sub Main()
    $hMessage = New Window(True, 0, 0, 800, 600)
    $hMessage.Border = 1
    $hMessage.Background = Color.Blue
    $hMessage.Foreground = Color.White
    $hMessage.Print("Surprise!")
    $hMessage.Show()
  End

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list