From: Mark M. <mie...@gm...> - 2011-07-05 15:29:11
|
On Tue, Jun 14, 2011 at 10:16 AM, Mark Miesfeld <mie...@gm...> wrote: > On Mon, Jun 13, 2011 at 8:48 AM, <os...@si...> wrote: > > > PS: The code is attached - a test dialog for sorting out how to check for > > valid numeric entry. It's pretty messy I'm afraid 'cos I'm doing a couple > of > > other things as well. > > Oliver, > > I reworked you program to restrict the user to entering a decimal > number with no more than 2 decimal places. It is a pretty good > implementation. > My implementation was okay, but I wasn't 100% happy with it. That, plus Oliver's idea to subclass the edit control to make the decimal number only available generically, lead me to create a better implementation. I put the example in the "Extra ooDialog Samples" package I just announced. Which can be downloaded from: https://sourceforge.net/projects/oorexx/files/ooDialog/ooDialog.Samples/ You will need to pick up the latest beta ooDialog 4.2.0 build also. After you install the samples package, the number only example will be found in ooDialog.samples.0.0.1\Controls\Edit\NumberOnly All the code for implementing the functionality is in a file: NumberOnlyEditEx.cls To include a decimal number only edit control in you programs, you just require that file: ::requires 'ooDialog.cls' ::requires 'NumberOnlyEditEx.cls' There is an example program: CalcMPG.rex that demonstrates how to use the NumberOnlyEditEx extension, along with a read me. The extension supports signed decimal numbers, so you can have an edit control that allows numbers like -1388.342 or +96.98. You specify how many decimal places to allow, and optionally whether to allow the sign character, through the initDecimalOnly() method: editGas = self~newEdit(IDC_EDIT_GAS) editGas~initDecimalOnly(3) initDecimalOnly() takes a second arg that allows the sign character, by default the sign character is not allowed: editGas = self~newEdit(IDC_EDIT_GAS) editGas~initDecimalOnly(2, .true) The functionality is implemented using the connectCharEvent() method. With this event connection, your event handling method get invoked each time a character is about to be sent to the edit control. In your event handler, you can examine which character is about to be sent to the edit control. If you reply .true, the character is then sent to the control. If you reply .false, the character is not sent. That is the proper way to implement this functionality. editGas = self~newEdit(IDC_EDIT_GAS) editGas~initDecimalOnly(3) editGas~connectCharEvent(onChar) In the event handler method in the dialog object, you just forward the onChar() message to the edit control: ::method onChar unguarded forward to (arg(6)) The NumberOnlyEditEx extension implements the initDecimalOnly() method and the onChar() event handler that is forwarded to from your dialog object. The actual arguments to the onChar() method are: ::method onChar unguarded use arg char, isShift, isCtrl, isAlt, misc, control The sixth argument, the 'control' argument above, is the actual Rexx edit control object. The technique for the decimal number only implementation could be used as a basis for implementing other types of restricted input edit controls. Telephone number only edit controls would be one example. -- Mark Miesfeld |