Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Testing for success of CreateObject?
Message
 
À
30/04/2009 14:02:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01397276
Message ID:
01397373
Vues:
168
Hi Matt,

I'd argue your object instantiation shouldn't be doing anything that should cause CreateObject to fail. If you have complex logic in the constructor or the constructor calls some complex function you should probably call that separately and deal with the errors accordingly.

Object instantiation failure is a pretty serious issue and one that in most cases you can't recover from effectively anyway, so the error should probably bubble up to an application level error handler.


+++ Rick ---

>I thought it would be a good idea to test for the success of a CreateObject call, and handle the case that would occur if it does not find the class for some reason. So, my code looks like what I show below.
>
>However, the problem is that you get a run-time error if the class 'searchcustom' is not found, so my test for < type('loSearch')='O' > is never executed . So, how should I test for the (unlikely, but possible) event that the requested cannot be found?
>
>
>
>Select Job_Info
>
> loSearch=createobject('searchcustom', 'Job_Info')
>
> if type('loSearch')='O'
>  loSearch.SearchClass1.cboFields2.value='QUOTED_BY'
>  loSearch.SearchClass1.type=2
>  loSearch.SearchClass1.init()
>  loSearch.show(1)
>  loSearch.release()
> else
>  messagebox('Error creating search object.', 0, 'Notice:')
> endif
> 
> goto bottom
> 
> thisform.recordPointerMovedParent()
>
>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform