• numEdit


    说明:  利用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.
  • 相关阅读:
    R-时空可视化
    zz温故知新:Tomcat调优&JVM内存性能调优
    《CarbonData》
    《RocketMQ》
    《LinuxTools》
    《为什么说 Prometheus 是足以取代 Zabbix 的监控神器?》
    《Zabbix》
    zz《百度地图商业选址》
    《Dapper》
    BZOJ 1601: [Usaco2008 Oct]灌水 最小生成树_超级源点
  • 原文地址:https://www.cnblogs.com/jijm123/p/10013772.html
Copyright © 2020-2023  润新知