[Gambas-user] Trying to do a "confirm" window (hopefully worded better)

Kchula-Rrit kchularrit at ...734...
Fri Oct 7 07:39:05 CEST 2005


  I'm trying to do a "confirm" window to ask the user if they really want to 
exit a program.  I'm not sure what I'm doing wrong, but it doesn't work.

        Right now, the program is just one window (FMain.form) with two 
buttons, created by the Gambas "New Project" command with "Standard Dialog" 
option.  I changed the name of the "OK" button to say "Exit", the "Cancel" 
button was left alone.

        When the user selects the "Exit" button, I want the main window to 
minimize and a "Confirm" window to show.  I have defined the "Confirm" window 
(FExit.form) to also have two buttons, called "Yes" and "No".  Selecting 
either button should close the "Confirm" window and return to the main 
program.  Selecting "Yes" should set an exit-flag in the main program, which 
then exits.  Selecting "No" should just return to the main program, which 
should restore the main window.

        The main window minimizes like it should but the confirm-window never 
shows.  When I "un-minimize" the main window, the buttons are blank and do 
not respond.

        Can anyone tell me what I'm doing wrong?  I'm using Gambas 1.9.20 in 
Debian Sarge from the www.linex.org packages, with "gb", "gb.debug", and 
"gb.qt" checked in the "components" property of the project file.

        I'm using a couple of blank WHILE loops to wait for the user to 
respond- is this appropriate?  I'm kind of new to event-driven programs and 
this has me stymied.

        Here's my main class file.
' Gambas class file  (FMain.class)

' TRUE = Exit, FALSE = Don't Exit
STATIC PUBLIC ExitFlag AS Boolean

STATIC PUBLIC SUB _init()

    ExitFlag = FALSE

END

STATIC PUBLIC SUB _exit()

END

PUBLIC SUB _new()

END

PUBLIC SUB _free()

END

STATIC PUBLIC FUNCTION Run() AS Boolean

    ' This function was created by Gambas
    DIM hForm AS Form

    hForm = NEW FMain

    RETURN hForm.ShowModal()

END

PUBLIC SUB btnExit_Click()

    ' Minimize Main Window
    ME.Minimized = TRUE

    ' Show "Confirm" Window
    FExit.Confirm()

    WHILE FExit.InExitScreen = TRUE
        ' Wait for user to respond to "Confirm" window
    WEND

    IF ExitFlag <> FALSE THEN
        ' User really wants to exit- do so.
        ME.Close
    ENDIF

    ' User goofed.  Return to main program.
    ' Restore Main Window
    ME.Minimized = FALSE
    ME.Refresh

END

PUBLIC SUB btnCancel_Click()

    ' Exit
    ME.Close()

END
==========================================

Here's my "Exit-class" file:
' Gambas class file (FExit.class)

' Exit window - just contains two buttons
PUBLIC ExitForm AS FExit

' "Yes" button - user really wants to exit.
PUBLIC btnYes AS Button

' "No" button - Oops, return to main.
PUBLIC btnNo AS Button

' TRUE = Wait for user to respond to "Confirm" window.
PRIVATE StayInLoop AS Boolean

' TRUE = User is in "Confirm" window.
PUBLIC InExitScreen AS Boolean


PUBLIC SUB _new()


    ' Filler
    InExitScreen = TRUE

END


PUBLIC SUB _free()


END

PUBLIC SUB Confirm()


    ' Display new window.
    ExitForm = NEW FExit
    FExit.Caption = "Confirm"
    ' (Try to) Display window.
    FExit.Show
    FExit.Refresh

    ' Create buttons.
    btnYes = NEW Button(ME)
    btnNo = NEW Button(ME)

    FExit.Refresh

    ' Set loop flag.
    StayInLoop = TRUE

    WHILE StayInLoop = TRUE
        ' Wait for user to respond.
    WEND

    ' Close window.
    FExit.Close

    ' Clear Exit-window flag.
    InExitScreen = FALSE

END

PUBLIC SUB Yes_Click()


    ' Set Program-Exit flag in main routine.
    FMain.ExitFlag = TRUE

    ' Clear loop-flag.
    StayInLoop = FALSE

END

PUBLIC SUB No_Click()

    ' Clear loop-flag.
    StayInLoop = FALSE

END

================================================




More information about the User mailing list