Delphi

本类阅读TOP10

·分布式网络考试系统原型分析及实现
·游戏外挂设计技术探讨①
·使用HOOK随心监视Windows
·Delphi 水晶报表打包解决
·试题库开发中非文本数据的处理
·如何将几个DBGRID里的内容导入同一个EXCEL表中....的问题
·如何使用Delphi设计强大的服务器程序
·工人线程中关闭窗体的实现
·用DLL方式封装MDI子窗体。
·支持XP下托盘栏气球提示的托盘单元

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
检查特殊字符的简单VCL

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

 

这是个很简单的组件,编写它的目的也很单纯,就是想解决数据录入时的特殊字符检查问题。一开始要写函数实现,不过觉得麻烦,后来就想到写一个简单的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写的。

:)




相关文章

相关软件