Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Open Forms
Message
De
19/04/2003 16:40:57
 
 
À
19/04/2003 14:23:54
Information générale
Forum:
Visual FoxPro
Catégorie:
CodeMine
Titre:
Divers
Thread ID:
00779204
Message ID:
00779529
Vues:
15
This message has been marked as the solution to the initial question of the thread.
Hi Gilles

>Sorry not to be clear enough...

No problem.

>I have a method in all my forms -> chgtheme()
>In my application class, I have another method settheme(). Every time this method in oApp object is launched, I would like to have all chgtheme methods launched in all open forms on the screen...
>
>I've tried to do subscribe(settheme,ThisForm,chgtheme) in each init method of forms and then Broadcast(settheme) from oApp object..

First, it does not appear that you have actually defined the system "state" that is "subscribed" to. So, you need to do something like :-
*-- [My Form Theme] is just the "name" of the state. You can call it what you want.
*-- .F. is the "initial" value of the state when defined.
*-- [chgTheme] is the method you want to be called. It defaults to [Refresh].
*-- This definition want to be placed early in the stack. I suggest 
*-- appMain.appApplication.createstates()

*-- The return value of the following call is the index of the [My Form Theme] state.
*-- You can record this to a property so that when you refer to this state in subsequent calls,
*-- it will be faster than providing the name of the state i.e., [My Form Theme] because the
*-- stateManager doesn't have to translate the name of the state back to its index (which it
*-- does each time unless you provide the originally assigned state index.

m.goStateManager.defineState([My Form Theme], .F., [chgTheme])
Now you have a system state defined. You have to "subscribe" each object to the state. As you know, you do this with the statemanager's subscribe method. So, in the Init of each form, you would do something like this :-
*-- The 1st parameter is the state name or the state index if you recorded it (see defineState)
*-- The 2nd parameter could be just "This" as you are calling from the form's Init.
*-- The 3rd parameter (not specified) is the Optional Override. If you don't specify
*-- a method value here, the value specified in the state you are subscribing to, in
*-- this case [chgTheme] will be used.

m.goStateManager.Subscribe([My Form Theme], ThisForm)
Finally, when you want to have the subscribed objects react, you do this in your application object's setTheme() method, like so :-
Function Application.setTheme()

*-- The 1st parameter is the name of the state. It could be the state's index value if recorded.
*-- You can specify optional parameters to pass to the method associated with the called method.
*-- In this case, the maximum number of parameters you can pass is two.

m.goStateManager.Broadcast([My Form Theme]) && uP1, uP2
So, when you want chgTheme to be launched in each of the subscribers, from any point your application, you just do as follows :-
m.goApp.setTheme()
This just issues the broadcast() instruction. Obviously, you could likewise just issue the Broadcast() instruction but, it would be best to keep this in the setTheme method as you may want to change things around downstream e.g., add parameters, specify a different method name to call in different circumstances etc.,

You may have to play around with this to get it going but this is the general strategy and should give you the result you require.

HTH

Best
-=Gary
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform