Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Execute code before closing form
Message
De
28/03/2007 16:05:19
Hans-Otto Lochmann
Dr. Lochmann Consulting Gmbh
Frankfurt, Allemagne
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
01209324
Message ID:
01209418
Vues:
23
>Hans,
>
>I'm sorry, but two problems caught my eye in this code:
>
>1) In Keypress Dodefault() we need to pass parameters.
>
>2) You may want to avoid repeating the same code in Release and QueryUnload. It could be a different method or close button should check for QueryUnload.
>
>

Hi Naomi,

first of all - you are NOT repugnant all (I checked the dictionary, 'cause I didn't even know that word), you are caring, considerate and really fast! And what I like most: openly and freely speaking!

to 1) - you're right, it has been my test version, but this is a weak excuse, I admit.

to 2) - you're right again, but to show you, why I did it, below there is a slightly modified version (including KeyPress). Of course you could have the messagebox with the question to the user in another procedure, which serves both methods (QueryUnload and Release), but it was faster that way: If you click the button or press ESC then you have the sequence - Init - Release - OnClose - Unload; if you press the CloseBox then you have the sequence - Init - QueryUnload - OnClose - Unload. That does it for me.

And of course the usual excuse, whenever I am caught with some sloppy work: It was just my test version....

Thanks for you attention, and until next time...

Hans
***********************************************************
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
    Activate Screen
    ? 'frmbase.Keypress()'
    If nKeyCode = 27 And nShiftAltCtrl = 0
      Nodefault
      Thisform.Release
      Return
    Else
      DoDefault(nKeyCode, nShiftAltCtrl)
    Endif
  Endproc

  Procedure Init
    Activate Screen
    Clear
    ? 'frmbase.Init()'
    If !DoDefault()
      Return .F.
    Endif
    With Thisform
      .lreleaseapproved = .F.
      .AutoCenter = .T.
      .AutoCenter = .F.
    Endwith
  Endproc

  Procedure OnClose
    Activate Screen
    ? 'frmbase.Onclose()'
    Messagebox('Do some useful code here!')
  Endproc

  Procedure QueryUnload
    Activate Screen
    ? 'frmbase.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()
        *-- I do not know, whether this is really needed here.
        DoDefault()
      Else
        .lreleaseapproved = .F.
        Nodefault
      Endif m.lnAnswer = 6
      *Else
      *  DoDefault()
      *Endif .lreleaseapproved = .F.
    Endwith
    Return
  Endproc

  Procedure Release
    Activate Screen
    ? 'frmbase.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()
        *-- I do not know, whether this is really needed here.
        DoDefault()
      Else
        .lreleaseapproved = .F.
        Nodefault
      Endif m.lnAnswer = 6
      *Else
      *  DoDefault()
      *Endif .lreleaseapproved = .F.
    Endwith
    Return
  Endproc

  Procedure Unload
    Activate Screen
    ? 'frmbase.Unload()'
    Nodefault
    *--- Do whatever needed at the very end like CLEAR EVENTS
    DoDefault()
  Endproc

  Procedure cmdexit.Click
    Thisform.Release()
  Endproc

Enddefine
***********************************************************
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform