Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referencing methods in apps
Message
 
 
À
11/03/1998 15:18:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00083992
Message ID:
00085229
Vues:
22
David,

If you want a global oApp that the whole world can see, just create it in your program startup:

private goApp
goApp = createobject( "MyApp" )

goApp.StartRunning()

Where StartRunning might create a form which could reference the goApp object with goApp.DoThis(). This is ok, but it "forces" an environment to be in place for the form, and it makes the form forever dependent on having a goApp object for it to use.

Another way of linking these objects that gives you more flexibility would be to pass a reference of the object to the form in the StartRunning:

do form TheForm with this

In the TheForm.Init() method:

lparameter oCaller
this.moCaller = oCaller && store reference to the object for later use

Then to use a method you do:

thisform.moCaller.DoThis()

You are still linking two objects with some particular public interface that needs to be in place, i.e. the caller object must have a DoThis() method, but you get away from forcing a particular name on that object

>How do I reference a method in an app created with CreateObject()?
>
>For example, if I have
>
>oApp = CreateObject( "MyApp")
>
>for which MyApp contains a method DoThis(), I can, within MyApp, successfully call this.DoThis(), but if later I have an object in a form opened by MyApp, I cannot figure out how to call that method.
>
>Is it possible, or do I have to keep DoThis() in a proc file?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform