Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Execute code before closing form
Message
From
29/03/2007 07:45:42
 
 
To
28/03/2007 15:11:18
Hans-Otto Lochmann
Dr. Lochmann Consulting Gmbh
Frankfurt, Germany
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01209324
Message ID:
01209614
Views:
20
>**************************************************
>oForm = Createobject('frmBase')
>oForm.Show(1)
>
>Define Class frmbase As Form
>
>  Caption = "FormBase"
>  KeyPreview = .T.
>  *-- Reflects the answer to the questions, whether the user wants to close the form.
>  lreleaseapproved = .F.
>  Name = "frmbase"
>
>  Add Object cmdexit As CommandButton With ;
>    Top = 120, ;
>    Left = 190, ;
>    Height = 27, ;
>    Width = 84, ;
>    Caption = "E\<xit", ;
>    Name = "cmdExit"
>
>  Procedure KeyPress
>    Lparameters nKeyCode, nShiftAltCtrl
>    If nKeyCode = 27 And nShiftAltCtrl = 0
>      Nodefault
>      Thisform.Release
>    Endif
>    DoDefault()
>  Endproc
>
>  Procedure Init
>    If !DoDefault()
>      Return .F.
>    Endif
>    With Thisform
>      .lreleaseapproved = .F.
>      .AutoCenter = .T.
>      .AutoCenter = .F.
>    Endwith
>  Endproc
>
>  Procedure OnClose
>    Messagebox('Do some useful code here!')
>  Endproc
>
>  Procedure QueryUnload
>    Local lnAnswer As Integer
>    With This As Thisform
>      If .lreleaseapproved = .F.
>        m.lnAnswer = Messagebox( ;
>          'Would you really like to close down?', ;
>          4+32+256+4096, .Caption)
>        If m.lnAnswer = 6
>          .lreleaseapproved = .T.
>          .OnClose()
>          DoDefault()
>        Else
>          .lreleaseapproved = .F.
>          Nodefault
>        Endif m.lnAnswer = 6
>      Else
>        DoDefault()
>      Endif .lreleaseapproved = .F.
>    Endwith
>    Return
>  Endproc
>
>  Procedure Release
>    Local lnAnswer As Integer
>    With This As Thisform
>      If .lreleaseapproved = .F.
>        m.lnAnswer = Messagebox( ;
>          'Would you really like to close down?', ;
>          4+32+256+4096, .Caption)
>        If m.lnAnswer = 6
>          .lreleaseapproved = .T.
>          .OnClose()
>          DoDefault()
>        Else
>          .lreleaseapproved = .F.
>          Nodefault
>        Endif m.lnAnswer = 6
>      Else
>        DoDefault()
>      Endif .lreleaseapproved = .F.
>    Endwith
>    Return
>  Endproc
>
>  Procedure Unload
>    Nodefault
>    *--- Do whatever needed at the very end like CLEAR EVENTS
>    DoDefault()
>  Endproc
>
>  Procedure cmdexit.Click
>    Thisform.Release()
>  Endproc
>
>Enddefine
>**************************************************
>
>
>works with all three: button click, close box click (top right) and ESC.
>
>Hans

I'd eliminate all that "Do you really want to close down" stuff unless something really terrible will happen if you close the form accidentally. It's just excess baggage.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform