</pre>
<table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor="#F3F3DE" bordercolor="#808000">
<tr>
<td width="100%"><pre><font COLOR="#000080"><i>////////////////////////////////////////////////////////////////////////</i></font>
<font FACE="Courier New">
<font COLOR="#000080"><i>// TNumEdit Control version 1.0 08-01-2000</i></font>
<font COLOR="#000080"><i>// Input : 0..9, -(1x) and the DecimalSeparator (1x)</i></font>
<font COLOR="#000080"><i>// This control can also round the value by #decimals</i></font>
<font COLOR="#000080"><i>//</i></font>
<font COLOR="#000080"><i>// (c) BeenSoft Http://surf.to/beensoft Mail : beensoft@yahoo.com</i></font>
<font COLOR="#000080"><i>////////////////////////////////////////////////////////////////////////</i></font>
<b>unit</b> NumEdit;
<b>interface</b>
<b>uses</b>
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
<b>type</b>
TNumEdit = <b>class</b>(TCustomEdit)
<b>private</b>
<font COLOR="#000080"><i>{ Private declarations }</i></font>
FAutoRounding : Boolean;
FRound : Boolean; <font COLOR="#000080"><i>// Rounding</i></font>
FRoundingDecimals : Integer; <font COLOR="#000080"><i>// Number of decimals for rounding</i></font>
FKeyPressed : Boolean; <font COLOR="#000080"><i>// Keypressed</i></font>
FAlignment : TAlignment;
<b>Function</b> RoundedText(aText : <b>String</b>) : <b>String</b>; <font COLOR="#000080"><i>// Perform the rounding</i></font>
<b>procedure</b> KeyPress(<b>var</b> Key: Char); <b>override</b>;
<b>procedure</b> DoExit; <b>override</b>;
<b>procedure</b> DoEnter; <b>override</b>;
<b>procedure</b> Change; <b>override</b>;
<b>public</b>
<font COLOR="#000080"><i>{ Public declarations }</i></font>
<b>Constructor</b> Create (AOwner : TComponent); <b>override</b>;
<b>procedure</b> CreateParams(<b>var</b> Params: TCreateParams); <b>override</b>;
<b>procedure</b> SetAlignment(Value: TAlignment);
<b>property</b> KeyPressed : boolean <b>read</b> FKeyPressed <b>write</b> FKeyPressed <b>default</b> False;
<b>property</b> Alignment: TAlignment <b>read</b> FAlignment <b>write</b> SetAlignment <b>default</b> taLeftJustify;
<b>published</b>
<font COLOR="#000080"><i>{ Published declarations }</i></font>
<font COLOR="#000080"><i>//new properties</i></font>
<b>property</b> AutoRounding : boolean <b>read</b> FAutoRounding <b>write</b> FAutoRounding <b>default</b> False;
<b>property</b> RoundingDecimals : Integer <b>read</b> FRoundingDecimals <b>write</b> FRoundingDecimals;
<b>property</b> Round : boolean <b>read</b> FRound <b>write</b> FRound <b>default</b> false;
<font COLOR="#000080"><i>//publishing properties declared in TCustomEdit </i></font>
<b>property</b> Anchors;
<b>property</b> AutoSelect;
<b>property</b> AutoSize;
<b>property</b> BiDiMode;
<b>property</b> BorderStyle;
<b>property</b> CharCase;
<b>property</b> Color;
<b>property</b> Constraints;
<b>property</b> Ctl3D;
<b>property</b> DragCursor;
<b>property</b> DragKind;
<b>property</b> DragMode;
<b>property</b> Enabled;
<b>property</b> Font;
<b>property</b> HideSelection;
<b>property</b> ImeMode;
<b>property</b> ImeName;
<b>property</b> MaxLength;
<b>property</b> OEMConvert;
<b>property</b> ParentBiDiMode;
<b>property</b> ParentColor;
<b>property</b> ParentCtl3D;
<b>property</b> ParentFont;
<b>property</b> ParentShowHint;
<b>property</b> PasswordChar;
<b>property</b> PopupMenu;
<b>property</b> ReadOnly;
<b>property</b> ShowHint;
<b>property</b> TabOrder;
<b>property</b> TabStop;
<b>property</b> Text;
<b>property</b> Visible;
<b>property</b> OnChange;
<b>property</b> OnClick;
<b>property</b> OnDblClick;
<b>property</b> OnDragDrop;
<b>property</b> OnDragOver;
<b>property</b> OnEndDock;
<b>property</b> OnEndDrag;
<b>property</b> OnEnter;
<b>property</b> OnExit;
<b>property</b> OnKeyDown;
<b>property</b> OnKeyPress;
<b>property</b> OnKeyUp;
<b>property</b> OnMouseDown;
<b>property</b> OnMouseMove;
<b>property</b> OnMouseUp;
<b>property</b> OnStartDock;
<b>property</b> OnStartDrag;
<b>end</b>;
<b>procedure</b> <b>Register</b>;
<b>implementation</b>
<b>Constructor</b> TNumEdit.Create (AOwner : TComponent);
<b>begin</b>
<b>Inherited</b> Create(AOwner);
SetAlignment(taRightJustify);
Text := '0';
<b>end</b>;
<b>procedure</b> TNumEdit.CreateParams(<b>var</b> Params: TCreateParams);
<b>const</b>
Alignments: <b>array</b>[Boolean, TAlignment] <b>of</b> DWORD =
((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));
<b>begin</b>
<b>inherited</b> CreateParams(Params);
<b>with</b> Params <b>do</b>
<b>begin</b>
Style := Style <b>or</b> ES_MULTILINE <b>or</b>
Alignments[UseRightToLeftAlignment, FAlignment];
<b>end</b>;
<b>end</b>;
<b>procedure</b> TNumEdit.SetAlignment(Value: TAlignment); <font COLOR="#000080"><i>//Set the Alignment</i></font>
<b>begin</b>
<b>if</b> FAlignment <> Value <b>then</b>
<b>begin</b>
FAlignment := Value;
RecreateWnd;<font COLOR="#000080"><i> //Force a redraw of the control</i></font>
<b>end</b>;
<b>end</b>;
<b>Function</b> TNumEdit.RoundedText(aText : <b>String</b>) : <b>String</b>; <font COLOR="#000080"><i>//Perform rounding the text</i></font>
<b>begin</b>
FmtStr(Result,'%0.'+ IntToStr(RoundingDecimals) +'f',[StrToFLoat(Text)]);
KeyPressed := false;
<b>end</b>;
<b>procedure</b> TNumEdit.Change;
<b>begin</b>
<b>if</b> <b>not</b> KeyPressed <b>then</b>
<b>begin</b>
<b>if</b> (Text <> '') <b>and</b> Round <b>then</b>
Text := RoundedText(Text);
<b>end</b>
<b>end</b>;
<b>procedure</b> TNumEdit.DoEnter; <font COLOR="#000080"><i>// Perform rounding when entering</i></font>
<b>begin</b>
<b>If</b> AutoRounding <b>then</b>
<b>if</b> (Text <> '') <b>and</b> Round <b>then</b>
Text := RoundedText(Text);
<b>end</b>;
<b>procedure</b> TNumEdit.DoExit; <font COLOR="#000080"><i>// Perform rounding when exiting</i></font>
<b>begin</b>
<b>if</b> (Text <> '') <b>and</b> Round <b>then</b>
Text := RoundedText(Text);
<b>end</b>;
<b>procedure</b> TNumEdit.KeyPress(<b>var</b> Key: Char);
<b>begin</b>
KeyPressed := true;
<b>Inherited</b> KeyPress(Key); <font COLOR="#000080"><i>// For user events</i></font>
<font COLOR="#000080"><i>//Check for Numeric and backspaces</i></font>
<b>if</b> <b>not</b> (Key <b>in</b> ['0'..'9', '-', DecimalSeparator,#8]) <b>then</b>
<b>begin</b>
KeyPressed := False;
key:=#0;
beep;
<b>end</b> <b>else</b> <font COLOR="#000080"><i>//Check for existing ofdecimalsepatator and '-'</i></font>
<b>if</b> ((Key = DecimalSeparator) <b>or</b> (key = '-')) <b>and</b> (Pos(Key, Text) > 0) <b>then</b>
<b>begin</b>
<b>If</b> Key = DecimalSeparator <b>then</b>
<b>begin</b>
SelStart := Pos(Key, Text);
SelLength := Length(Text);
<b>end</b>;
key:=#0;
<b>end</b> <b>else</b> <font COLOR="#000080"><i>// If '-' then first check position at front</i></font>
<b>if</b> (Key = '-') <b>and</b> (Selstart <> 0) <b>then</b>
<b>begin</b>
key:=#0;
beep;
<b>end</b>;
<b>end</b>;
<b>procedure</b> <b>Register</b>;
<b>begin</b>
RegisterComponents('Beensoft', [TNumEdit]);
<b>end</b>;
<b>end</b>.</pre>
</td>
</tr>
</table>