Re: OOP style
- From: "swansnow" <schultz@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: 30 Aug 2005 05:46:20 -0700
> The root of all evil, if not avoided, is putting functionality > > into event handler methods of forms.
I'm interested in hearing more about this.
Say I have a form, and I need to limit the kind of characters allowed
in the edit controls. So I hook each one up to the following event
handler (below). Are you saying that I shouldn't do that? Instead, I
should put this code into another unit (maybe a reusable library), and
then simply call it from the event handler?
When I was a kid, there was a set of book called Choose Your Own
Adventure, which pretty much had cross references to other pages based
on what choices you made in the story (kind of a low-tech RPG). I
didn't like these books, because flipping pages all the time was
mentally disorienting for me, and the stories weren't good enough to
make all that effort worthwhile :)
At some point, calling functions starts feeling like a Choose Your Own
Adventure. You go look to see what this method is doing, and it sends
youto another one, and then you get sent to another one... It's hard to
build a mental model when you keep following references like that. Or
is it that I'm just a victim of bad design?
{ Only numbers, lowercase or capital letters allowed}
procedure TForm1.AlphaNumericOnlyKeyPress(Sender: TObject; var Key:
Char);
begin
if (not(key in [#127, #8])) and {del bs}
(not(key in [#65..#90])) and {A-Z}
(not(key in [#97..#122])) and {a-z}
(not(key in [#48..#57])) {0-9}
then begin
ShowMessage('Invalid Character, Please use letters and numbers
only.');
key := #0;
end;
end;
.
- Follow-Ups:
- Re: OOP style
- From: J French
- Re: OOP style
- From: Maarten Wiltink
- Re: OOP style
- References:
- OOP style
- From: swansnow
- Re: OOP style
- From: Bjørge
- OOP style
- Prev by Date: Re: HTTPS using Indy
- Next by Date: Re: terminal services compatibility
- Previous by thread: Re: OOP style
- Next by thread: Re: OOP style
- Index(es):
Relevant Pages
|