中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 控件开发
检查特殊字符的简单VCL
作者:40Star 时间:2001-10-27 10:35 出处:互联网 责编:chinaitpower
              摘要:检查特殊字符的简单VCL

 

这是个很简单的组件,编写它的目的也很单纯,就是想解决数据录入时的特殊字符检查问题。一开始要写函数实现,不过觉得麻烦,后来就想到写一个简单的VCL来遍历Form上所有的组件的方法。这个VCL目前只是检查所有的TEdit和TComboBox组件,有兴趣的朋友可以自己扩充功能。

我想这个VCL对于编写数据库程序的人员来说还是有一点帮助的,比如对单引号的Check。

想要检查什么符号只要在属性中设置一下就搞定,而且运行时只需要执行一个Checking函数,他就会自动检查咯。

它的另一个作用就是可以作为编写VCL的简单入门例程。

 

unit SymbolChecker;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls,StdCtrls,Dialogs,StrUtils;

type
  TCheckControl = (cTEdit, cTComboBox);
  TCheckControls = set of TCheckControl;

  TSymbolChecker = class(TComponent)
  private
    { Private declarations }
    FActive: boolean;
    FCheckControls:TCheckControls;
    FCheckString:String;
    procedure SetActive(Value: boolean);
    procedure SetCheckControls(Value: TCheckControls);
    procedure SetCheckString(Value: String);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    procedure Checking();
    property Active: boolean read FActive write SetActive default false;
    property CheckControls: TCheckControls read FCheckControls write SetCheckControls default [cTEdit, cTComboBox];
    property CheckString: String read FCheckString write SetCheckString;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyVCL', [TSymbolChecker]);
end;

constructor TSymbolChecker.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  CheckControls := [cTEdit, cTComboBox];
end;

{ Set property Active Value }
procedure TSymbolChecker.SetActive(Value: boolean);
begin
  if Value = FActive then exit;
  FActive := Value;
end;

{ Set property CheckControls Value }
procedure TSymbolChecker.SetCheckControls(Value: TCheckControls);
begin
  if Value = FCheckControls then exit;
  FCheckControls := Value;
end;

{ Set property CheckString Value }
procedure TSymbolChecker.SetCheckString(Value: String);
begin
  if Value = FCheckString then exit;
  FCheckString := Value;
  if Trim(FCheckString) = ' then SetActive(false);
end;

procedure TSymbolChecker.Checking();
var
   I,J:integer;
begin
   { property Active=true then execute }
   if FActive then
   begin
      { property CheckTEdit=true then execute }
         for I:= 0 to owner.ComponentCount - 1 do
         begin
            { Check TEdit }
            if (owner.Components[I] is TEdit) and (cTEdit in CheckControls) then
            begin
               for J :=1 to Length(Trim(FCheckString)) do
               begin
                  if pos(MidStr(Trim(FCheckString),J,1),TEdit(owner.Components[I]).Text)>0 then
                  begin
                     ShowMessage('error symbol!');
                     TEdit(owner.Components[I]).SetFocus;
                     exit;
                  end;
               end;
            end;
            { Check TComboBox }
            if (owner.Components[I] is TComboBox) and (cTComboBox in CheckControls) then
            begin
               for J :=1 to Length(Trim(FCheckString)) do
               begin
                  if pos(MidStr(Trim(FCheckString),J,1),TComboBox(owner.Components[I]).Text)>0 then
                  begin
                     ShowMessage('error symbol!');
                     TComboBox(owner.Components[I]).SetFocus;
                     exit;
                  end;
               end;
            end;
         end;
   end;
end;

end.


最后要说明一点的是它是用Delphi6写的。

:)

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有