Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Command Group Value
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00606848
Message ID:
00609076
Vues:
21
Rich,

First - buttons ought to do their own thing, they should be responsible for themselves. You have two ways to do this, and there strong opinions about them, I kinda moderate between them. 1) you can put all of the code in the Click() method of the button, this makes it a fully self contained entity. 2) the Click() of the button always calls a custom method of it's container (or form). I use both in various places depending on the situation. If I have a codeblock that can be executed from something else in addition to the Click() then I always use #2 and both places call to the same method:
cmdX.Click()
dodefault()
thisform.DeleteClient()
return


oSomethingElse.SomeOtherMethod()
...
thisform.DeleteClient()
...
return
If the codeblock is short and not needed to be called from elsewhere I'm likely to just stuff it into the cmd.Click() instead of going through all of the effort to create a method. If I find later on that the codeblock needs to be reused I instantly promote it to a method of the common container.

In your case I think it's best that you avoid the CASE statement entirely. With it you are strongly coupling the buttons to the command group. I don't see a real big need to put all of that switching logic in the cmg.Click(). Why not have each button 1) do it's own thing or 2) call
this.parent.DoMyThingForMe() where the cmg just has a uniqely named method for each button like DeleteClient(), AddClient(), etc. I think this makes you code much more readable, you can see at a glance from the cmd.Click() what's going to happen you don't have to go off to the cmg.Click() to find that information.

Another big downside to your CASE statement comes if you move a button. Then you have your buttons out of sequence or you have to move your CASEs around.


>Ok, here’s what I’m trying to do. The CLICK event in the cmg has a case statement:
>
>DO CASE
>CASE THIS.VALUE = 1
> * Do thing 1
>CASE THIS.VALUE = 2
> * Do thing 2
>CASE THIS.VALUE = 3
> * Do thing 3
>CASE THIS.VALUE = 4
> * Do thing 4
>ENDCASE
>
>There are other situations in which I want the code associated with the case to execute. These are associated with another form in the form set. I don’t want the second form to be concerned with what happens when the button is clicked, I just want the action to occur.
>
>There are dozens of ways to do this, but I’m interested in finding the most elegant or best in terms of the object model. Being the neophyte that I am, this has become an exercise in understanding the basics. I really appreciate your help!
df (was a 10 time MVP)

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

Click here to load this message in the networking platform