Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enclose every createobject with try catch?
Message
 
 
À
10/04/2018 14:42:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
01659292
Message ID:
01659298
Vues:
46
>>>>Hi,
>>>>
>>>>Do you think it is a good practice to enclose every case where the code opens a form (sample code below) with the Try Catch?
>>>>
>>>>
>>>>local oForm
>>>>oForm = newobject('my_form','my_form_lib.vcx')
>>>>if type('oForm') = "O" and !isnull( oForm)
>>>>   oForm.show()
>>>>endif
>>>>
>>>>
>>>>If there is a problem, whatever, a run-time error happens on NewObject, so checking for type and isnull is of little help. If I enclose the entire code in Try Catch, the error will be displayed.
>>>>
>>>>But I am not sure if adding so much code (in every case) is worth the 'trouble'
>>>>
>>>>TIA
>>>
>>>In my Form Handler class, I have a FormOpen method for this. It also make sure that the form is added to the Forms collection, and checks if the form can be opened more than once, plus a few other things.
>>
>>I am curious to how you handle problems with the FormOpen method. Could you give a sentence or a line/two to show how you can prevent a run-time error with this method? Thank you.
>
>This code was made before Try-catch, or at least before I became comfortable with it. It as never caused any problem so far. Here it is, unfortunately I don't have the time to go into details.
>
>
Lparameters tcClass, tcClasslibrary, tnModal, tvOption, toParameter, tvParameter
>
>Local lcClassLib, lcClassName, llCheckOpen, llCheckPrimary, llReturn, loForm, loFormRef
>m.loFormRef = .Null.
>m.lcClassName = Upper(m.tcClass)
>m.lcClassLib = m.tcClasslibrary
>*
>*!*   tvOption:
>*!*   0 or .F. = Open the form
>*!*   1 = If form already open select it
>*!*   "Recordkey" = If form with same recordkey is open, select it
>*
>If Vartype(m.tnModal) # [N]
>   m.tnModal = 0
>Endif
>*
>Do Case
>   case empty(tvOption)
>      m.llCheckOpen = .F.
>   Case Vartype(m.tvOption) = [N]
>      m.llCheckOpen = m.tvOption = 1
>   Case Vartype(m.tvOption) = [C]
>      m.llCheckOpen = .T.
>      m.llCheckPrimary = .T.
>Endcase
>*
>If m.llCheckOpen
>   For Each m.loForm In _Screen.Forms
>      If Upper(m.loForm.Class) == m.lcClassName
>         If m.llCheckPrimary
>            If m.loForm.oBusiness.Recordkey == m.tvOption
>               m.loFormRef = m.loForm
>            Endif
>         Else
>            m.loFormRef = m.loForm
>            Exit
>         Endif
>      Endif
>   Endfor
>   m.loForm = .Null.
>Endif
>*
>If Vartype(m.loFormRef) # [O]
>   Do Case
>      Case Pcount() = 6
>         m.loFormRef = Newobject(m.lcClassName, m.lcClassLib, [], m.toParameter, m.tvParameter )
>      Case Pcount() = 5
>         m.loFormRef = Newobject(m.lcClassName, m.lcClassLib, [], m.toParameter )
>      Case Pcount() >2
>         m.loFormRef = Newobject(m.lcClassName, m.lcClassLib )
>   Endcase
>Endif
>*
>m.llReturn = Vartype(m.loFormRef) = [O]
>*
>If m.llReturn
>   m.loFormRef.Show(m.tnModal)
>Else
>   m.loFormRef = .Null.
>Endif
>*
>Return m.loFormRef
Thank you very much for sharing. I will review and see if it applies to my form(s).
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform