Path: utzoo!attcan!uunet!lll-winken!xanth!indri!unmvax!tut.cis.ohio-state.edu!bloom-beacon!apple!well!odawa From: odawa@well.UUCP (Michael Odawa) Newsgroups: comp.sys.mac.programmer Subject: Re: Who has hacked numeric TEdit?. Message-ID: <11722@well.UUCP> Date: 18 May 89 08:19:19 GMT References: <1076@mailrus.cc.umich.edu> Reply-To: odawa@well.UUCP (Michael Odawa) Organization: Simple Software, Mill Valley, CA Lines: 47 In article <1076@mailrus.cc.umich.edu> cash@csmil.umich.edu (Howard Cash) writes: > Who is willing to part with the code for an editable text item > that only accepts valid numbers (real or integer)? You can intercept the keystrokes in the FilterProc you call with ModalDialog. Then peek at every key event as it comes in. If it's not a digit, change the event into a nullEvent and mark it as handled: function AddFilter (Dlg: DialogPeek; var CE: EventRecord; var itemHit: integer): boolean; var begin AddFilter := false; if CE.what in [keyDown, autoKey] then if CE.modifiers = 0 then if not (BitAnd(CE.message, $00ff) in ['0'..'9']) then begin AddFilter := true; CE.what = nullEvent; end; { if not (BitAnd(CE.message, $00ff) in ['0'..'9']).. } end; { AddFilter } procedure MainDlgProc; var ItemNo; begin . . ModalDialog(@AddFilter, itemNo); . . end; > For an example, try the PRINT command in almost any application. The Print dialog is a special dialog that requires more effort to hack. You need to read Tech Note 95 to learn about this. > Free chocolate at my place for the winning respondent. Just send it to me over the net. :-) Michael Odawa Simple Software odawa@well.uucp