Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hide command button, but still make it Click?
Message
 
To
22/06/2001 09:36:11
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00522206
Message ID:
00523516
Views:
10
Craig,

>>You could also just put
>ThisForm.cmdButton.Click()
>in your Timer event.. If you explicitly call it like that, it doesn't matter if the button is enabled/disabled, showing/hidden, etc.

>>The point that Thom was making is that this isn't good OOP. One control should not know about another.

Thank you sir. To expand a wee bit further; if you code multi-tier systems, processing (aka business) code NEVER goes into an interface control.

The implication of the original message in this thread is that there is some code in the click event of a command button that transcends the functionality of the button. If the developer ever decides to perform some kind of significant enhancement or translation of the application (i.e. a change in interface design or major addition to the functionality of the application) it will be much easier to do the rewrite if business logic is not written in the events and methods of interface controls.

Put it this way:

Ver 1.0
***THISFORM.cmdBtn1.Click()
[earth-shaking code goes here]
Ver 1.1.b
***THISFORM.cmdBtn1.Click()
[earth-shaking code still here]

***THISFORM.tmrTimer1.Timer()
WITH THISFORM
  .cmdBtn1.Click()
ENDWITH
Ver 3.1.13.c
***THISFORM.cmdBtn1.Click()
[earth-shaking code still here]

***THISFORM.tmrTimer1.Timer()
WITH THISFORM
  .cmdBtn1.Click()
ENDWITH

*** fifteen other controls, methods and events reference THISFORM.cmdBtn1.Click()
Ver 8.0.1

THISFORM.cmdBtn1 is scrapped...
Sixteen pieces of code, which all referenced the command button are now broken and have to be fixed.



If instead, the earth-shaking code was in its own method (or even in its own class):
*** in Earth_Shaking_Stuff.prg
DEFINE CLASS Earth_Shaking_Stuff AS CUSTOM

	FUNCTION Earth_Shaking_Code
	
		[earth-shaking code]
	
	RETURN(.T.)
ENDDEFINE


*** in THISFORM
*INIT()
IF ATC("Earth_Shaking_Stuff", SET("LIBRARY")) = 0
  SET CLASSLIB TO Earth_Shaking_Stuff.prg
ENDIF
THIS.oShakeItBaby=CREATEOJBECT("Earth_Shaking_Stuff")


* METHOD cmdBtn1.Click()
THIS.oShakeItBaby.Earth_Shaking_Code()
RETURN


***THISFORM.tmrTimer1.Timer()
THIS.oShakeItBaby.Earth_Shaking_Code()


*** fifteen other controls, methods and events
THIS.oShakeItBaby.Earth_Shaking_Code()
As silly as the example seems, I've seen code that wrapped around itself, doing pretty much what was seen in the first series of toung-in-cheek examples. When a major change in the form's functionality was required, I wound up making exactly the kind of change you see here.

Moral of the story: keep the business logic code out of the interface.

Regards,
Thom C.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform