Re: Set the CheckBox.Checked without the OnClick being called
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Sun, 10 Jun 2007 11:33:00 -0500
John Dough wrote:
On Sat, 09 Jun 2007 16:43:07 +0200, Fons
<fonzzzNO@xxxxxxxxxxxxxxxxxxx> wrote:
Mine is the hard way ?
Look at the amount of code you used...
Then look at the amount I used.
You didn't finish the entire application in that post, did you? You only gave one (half) example of using your global variable. How many times do you think it's really going to be used in the program?
Consider this. To implement your solution, we need a global variable, some piece of shared state information that the entire program needs to be aware of in order for the program to work properly. To make the program aware of that variable, every single event handler needs to be prefixed with the two instructions to check the variable and exit. That's increasing the coupling in your program. Then, every place in the program that needs to set a property needs to be wrapped with two lines (or possibly five, with a try-finally block) to set and reset the variable. Some of that overhead can be saved by assigning multiple properties within the same block of code.
Now look at Fons's way. He has lots more setup code, but that code never has to be looked at again. He can stow it away in a unit and not think about it anymore, knowing that it's already been tested. There's no global state information to keep track of. The big win is in the event handlers: They don't have to change at all! Where you're adding two instructions to each one to make sure it's aware of the possibility that it's not really supposed to run, Fons makes sure that the event handlers never even get called in the first place, so they don't have to consider whether they should run. Then, to set the properties, there are no additional lines of code required. Instead, each assignment statement is replaced by a call to the SetControlData procedure.
The amount of code _added_ to Fons's program is constant -- just the code in that one unit. The amount of code added to your program is linear in the number of event handlers and the number of property assignments.
How much time did you spend in testing and getting it to work the way
you wanted to? How much time did you spend typing in all those lines?
It's mostly copy and paste after the first procedure's finished, I hope. And it's not like it's a hard procedure to test, either.
I spent about 15 seconds from start to finish...
It took you just 15 seconds to add the extra code to all your event handlers? How did you even _find_ all the event handlers in that amount of time? How do you know you didn't miss one?
and it worked perfectly the first time.
Except that you didn't reset the variable to False...
--
Rob
.
- Follow-Ups:
- References:
- Set the CheckBox.Checked without the OnClick being called
- From: Fons
- Re: Set the CheckBox.Checked without the OnClick being called
- From: John Dough
- Re: Set the CheckBox.Checked without the OnClick being called
- From: Fons
- Re: Set the CheckBox.Checked without the OnClick being called
- From: John Dough
- Re: Set the CheckBox.Checked without the OnClick being called
- From: Fons
- Re: Set the CheckBox.Checked without the OnClick being called
- From: John Dough
- Set the CheckBox.Checked without the OnClick being called
- Prev by Date: Editing XML
- Next by Date: Re: Set the CheckBox.Checked without the OnClick being called
- Previous by thread: Re: Set the CheckBox.Checked without the OnClick being called
- Next by thread: Re: Set the CheckBox.Checked without the OnClick being called
- Index(es):