zoukankan      html  css  js  c++  java
  • VCL编写笔记整理


    unit hzqEdit1;

    interface

    uses
      SysUtils, Classes, Controls, StdCtrls;

    type
      TEditDataType = (dtpString, dtpInteger, dtpFloat);
      ThzqEdit = class(TEdit)
      private
        FDataType: TEditDataType;
        Fprecision: Integer;
        procedure KeyPress(var Key: Char); override;
        procedure SetDataType(const Value: TEditDataType);
      protected
      public

      published
        property DataType: TEditDataType read FDataType write SetDataType default dtpString; //设置输入的数据类型
      end;

    procedure Register;

    implementation

    procedure Register;
    begin
      RegisterComponents('Hzq', [ThzqEdit]);
    end;

    procedure ThzqEdit.SetDataType(const Value: TEditDataType);
    begin
      FDataType:=Value;
    end;

    procedure ThzqEdit.KeyPress(var Key: Char);

    begin
      case FDataType of
        dtpInteger:  //如果是整数
        begin
          if not (Key in ['0'..'9', '-', #8, #13, #35, #39]) then
            Key := #0;
          if (Key = '-') and ((Pos('-', Text) > 0) or (SelStart <> 0)) then
            Key := #0;
        end;
        dtpFloat:  //如果是符点数
        begin
          if not (Key in ['0'..'9', '.', '-', #8, #13, #35, #36, #37, #39]) then
            Key := #0;
          if (Key = '.') and (Pos('.', Text) > 0) then
            Key := #0;
          if (Key = '-') and ((Pos('-', Text) > 0) or (SelStart <> 0)) then
            Key := #0;
        end
      end;
      inherited KeyPress(Key); //调用父类的KeyPress方法
    end;

    end.

    打开delphi自带的Image Editor(ToolsàImage Editor),新建一个组件资源(fileànewàComponent Resource File (.dcr)),在弹出的窗口中右键单击new新建一个bitmap位图资源调整好位图的大小(我们用24*24)和色深后确定,双击建立好的位图名字还是做图(做图工具的使用基本和windows自带的画图程序差不多,这里略过),完成后我们需要为位图文件另取一个名字(右键点击bitmap),因为delphi强制要求这个位图的名字要和组件的名字一样,并且要全部大写,这里我们就取为:TCLOCK。最后保存这个资源文件到我们的组件包(dpk文件)目录,命名为ClockDcr.dcr。最后在Clock的代码中的interface部分加入一个编译器开关:{$R ClockDcr.dcr}然后重新编译更新组件

  • 相关阅读:
    Dom对象,控制html元素
    运算符总结
    数组
    变量命名规则
    css实现气泡说明框
    深入理解CSS中的层叠上下文和层叠顺序
    jquery书写
    二级导航
    iis配置
    Android ListView无法触发ItemClick事件
  • 原文地址:https://www.cnblogs.com/yzryc/p/6329492.html
Copyright © 2011-2022 走看看