说明: 利用tedit扩展的数字编辑框,允许设置正负、小数点等
(The digital edit box using tedit extended, allowing the set of positive and negative, the decimal point)
unit numEdit; interface uses SysUtils, Classes, Controls, StdCtrls; type TnumEdit = class(TEdit) private { Private declarations } fallowe:boolean; fallownegative:boolean;//允许负数 fallowpoint:boolean; fallowAll:boolean; protected { Protected declarations } procedure KeyPress(var Key: Char);override; public { Public declarations } function asint:integer; function asfloat:double; published { Published declarations } property allowe:boolean read fallowe write fallowe default false; property allownegative:boolean read fallownegative write fallownegative default false; property allowpoint:boolean read fallowpoint write fallowpoint default false; property allowAll:boolean read fallowall write fallowall default false; end; procedure Register; implementation procedure Register; begin RegisterComponents('System', [TnumEdit]); end; { TnumEdit } function TnumEdit.asfloat: double; var tmpf:double; begin try tmpf:=strtofloat(text); except tmpf:=-1; end; result:=tmpf; end; function TnumEdit.asint: integer; var tmpn:integer; begin try tmpn:=strtoint(text); except tmpn:=-1; end; result:=tmpn; end; procedure TnumEdit.KeyPress(var Key: Char); begin inherited; if fallowall then exit; if not (((ord(key)>=48) and //数字 (ord(key)<=57)) or // (ord(key)=8) or //删除 ((ord(key)=46) and fallowpoint) or //. ((ord(key)=45) and fallownegative) or //- (((ord(key)=101) or (ord(key)=69)) and fallowe))//e then key:=#0; end; end.