Re: OOP style



> 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;

.



Relevant Pages

  • Re: CommandBarButton not getting deleted in MS Word
    ... Assuming that the buttons are same and only functionality differs, ... I am actually developing the plugin for both Word and Outlook applications. ... overwriting the click event handler for Outlook. ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: application security for users
    ... >> is the best most transparent way to do this. ... >> the routine swallows the event, if go, it passes the event thru? ... > checking functionality in the event handler for that Action. ... use this as an alternative to the checks in the event handler. ...
    (comp.lang.java.programmer)
  • Re: Executing An External Forms Event Procedure
    ... Because an event handler is designed to respond to a specific event raised from an object, calling the function directly has nothing ... as mentioned earlier a separate method should be employed, ... can remain in the event handler while the generic functionality can be shifted to the new method. ...
    (microsoft.public.vb.general.discussion)
  • Re: Limit Document Versions
    ... You cannot prune versions ootb. ... But you could write an event handler on the ... document library to deliver this functionality pretty easily. ... Nige. ...
    (microsoft.public.sharepoint.portalserver)
  • RE: Attach List event handler to a custom list
    ... Ted is correct that the event handlers are only usable in Document Libraries, ... Can we attach an event handler to the custom list in order to do ... >> achieve the same functionality? ...
    (microsoft.public.sharepoint.portalserver.development)