Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Repeating piece of code
Message
De
02/04/2013 13:29:24
 
 
À
02/04/2013 09:20:24
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01569704
Message ID:
01569763
Vues:
67
>>It would be very useful because when you write inside a procedure it will not work,
>>if inside the procedure there are lines as thisform.command1.click, etc.
>
>Not sure what you mean when you say the call to the statement "thisform.command1.click" will not work when called. You are correct that the "click" event is not called when you execute that statement; but the code in the method "click" that you enter will be executed when you call the statement.
>
>I know that some say that you should never put code in the the event methods -- but then if this is followed to the extreme then there would never be any code there... So what is the difference in the two different calls - the first with the code embedded in the click method:
>
>
>PROCEDURE Click
>WAIT WINDOW "Some code lines" NOWAIT
>ENDPROC
>
>
>The second has a call to an external procedure:
>
>
>FUNCTION Click
>DO CalledByClick
>ENDFUNC
>
>
>
>
>PROCEDURE CalledByClick
>WAIT WINDOW "Some code lines" NOWAIT
>ENDPROC
>
>
>I do not see any difference in the above except that there is another calling layer in the second. I routinely place code into the event methods and then will call these directly if applicable. For instance, if I have a 'Save' buttton then I add the code to perform the save into the click method of this button. Then if elsewhere I need to call the code to perform the save operation, then I will call "thisform.cmdSave.Click()".

The difference is that with the operational code in the control's Click method, you're committed to that control and you end up with calls to Click methods, which to me are both ugly and a sign of weak design.

Putting code in button.Click that has to do with the button itself (changing a caption, disabling, etc.) makes sense to me. But code that's about something else belongs in a method devoted to whatever that "else" is.

In the example you gave, I would have a form-level Save method, called from the button's Click, from the Save item on the menu, from the Save button on the toolbar and anywhere else that Save is the appropriate operation. I think that's much easier to understand for the person taking over the code and much easier to maintain as things change.

Tamar
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform