检查特殊字符的简单VCL
来源:互联网 发布:java. 大数据 编辑:程序博客网 时间:2024/06/05 20:38
这是个很简单的组件,编写它的目的也很单纯,就是想解决数据录入时的特殊字符检查问题。一开始要写函数实现,不过觉得麻烦,后来就想到写一个简单的VCL来遍历Form上所有的组件的方法。这个VCL目前只是检查所有的TEdit和TComboBox组件,有兴趣的朋友可以自己扩充功能。
我想这个VCL对于编写数据库程序的人员来说还是有一点帮助的,比如对单引号的Check。
想要检查什么符号只要在属性中设置一下就搞定,而且运行时只需要执行一个Checking函数,他就会自动检查咯。
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写的。
:)
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>- 检查特殊字符的简单VCL
- 检查特殊字符的简单VCL
- 检查特殊字符的简单VCL
- 检查密码是否包含特殊字符
- *正则表达式检查是否含有特殊字符
- 检查用户名是否含义特殊字符
- Java Web 一些特殊字符的过滤(appscan检查的安全问题)
- 很简单的过滤特殊字符的函数
- 简单算法_字符检查
- Java简单转义特殊字符
- 搜索框输入特殊字符后台的简单处理方式
- 关于input自动过滤特殊字符的简单方法
- 关于input自动过滤特殊字符的简单方法
- html的特殊字符
- 特殊的空格字符
- html的特殊字符
- 特殊字符的处理
- shell的特殊字符
- 如何获取局域网中的所有 SQL Server 服务器
- MYSQL数据库常用命令集合
- 定义链接的样式CSS
- 动态数组介绍----Delphi
- 典型的三行二列居中高度自适应布局
- 检查特殊字符的简单VCL
- 让你完全认识MySQL数据库中Show命令用法
- 使用css直接定义input标签
- Data-Browse型Data-Aware控件的制作
- 无法远程登入MySQL数据库的三种解决办法
- 用!important解决IE和Mozilla的布局差别
- 使用TNMSMTP控件在需认证服务器上发送邮件
- Ubuntu操作系统下安装MySQL数据库的方法
- 对CSS的Class及Id的规范化命名