Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can execute a button click method without showing the fo
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01671046
Message ID:
01671141
Vues:
59
>So, whatever code is there in the click() event, would be there in the my_click_event_code() as well. Wouldn't it?

That is right, but think about this:

When you originally design your form you have two buttons in it that need to do the same thing, so, there is nothing wrong with:
procedure button1.click()
	* Do the task
endproc

procedure button2.click()
	button1.click()
endproc
Now button1 needs to do something additional that button2 should not do, your first thought might be to add the code to "* Do the task", then you need to find where else button1.click() is called, and do something, like copying and pasting the original "*Do the task". Now you start having problems that will grow as you have more objects, some of them not even in the original form, all calling to the button1.click(), you will need to find and correct them all. On the other hand, if your code was something like:
procedure theTask()
	* Do the task
endproc

procedure button1.click()
	theTask()
endproc

procedure button2.click()
	theTask()
endproc
If you now want to change button1 behaviour you can just do:
procedure theTask()
	* Do the task
endproc

procedure theAdditionalTask()
	* Do the additional task
endproc

procedure button1.click()
	theTask()
	theAdditionalTask()
endproc

procedure button2.click()
	theTask()
endproc
Now button2.click() and any other object/code that was calling "theTask" remains untouched, so you will not need to remember or find anything, you just change the behaviour of the one object that needed to change it's behaviour.

If you go a step further and you put all the behavioral code outside of your form, let's say in a prg, and then you call the code on that prg, you get as an added bonus that now your code can be called from anywhere, and you do not need to instantiate one form to call a method.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform