Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Instantiate a class in code
Message
De
21/03/2024 12:14:55
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01687754
Message ID:
01687758
Vues:
42
>>>Hi,
>>>
>>>Typically - in my VFP9 application - business classes are instantiated in the LOAD of the form. I usually drop the class object on the form - at design time - and the class is instantiated automatically in the LOAD of the form.
>>>
>>>Now I need to instantiate an object of a class in code (in a PRG file). So far, the only way I found I could do it is as follows:
>>>
>>>
>>>oObject = NEWOBJECT("class_name","class_name_lib.vcx" )
>>>
>>>
>>>Can you suggest a better way to instantiate the class?
>>
>>There's a way without the code, but it's tricky. I had to use it when I wanted a bizobject added to a container or page. Namely, I'd add a property which would have this value:
>>
=NEWOBJECT("class_name","class_name_lib.vcx" )
>>Don't remember whether I had to put all of it except the equal sign in parentheses. This made the object instantiate before any other code in the container or page.
>>
>>Unless you need this, what you're doing is already the best way.
>
>First, thank you for your message.
>
>I need this class instantiated in the Main.prg. So, as far as I know, there is nothing to add this class to.
>I suppose - unless someone suggest a better than mine approach - I will keep it in code, as I indicated in the initial post.

You write "there is nothing to add this class to", but you can always use _screen as a container.
_screen.AddProperty("oBject", NewObject('class_name', 'class_lib.vcx'))
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform