檢查特殊字元的簡單VCL (轉)
這是個很簡單的,編寫它的目的也很單純,就是想解決資料錄入時的特殊字元檢查問題。一開始要寫實現,不過覺得麻煩,後來就想到寫一個簡單的VCL來遍歷Form上所有的元件的方法。這個VCL目前只是檢查所有的TEdit和TComboBox元件,有興趣的朋友可以自己擴充功能。
我想這個VCL對於編寫的人員來說還是有一點幫助的,比如對單引號的Check。
想要檢查什麼符號只要在屬性中設定一下就搞定,而且執行時只需要一個Checking函式,他就會自動檢查咯。
它的另一個作用就是可以作為編寫VCL的簡單例程。
unit SymbolChecker;
interface
uses
, 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); overr;
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.
最後要說明一點的是它是用6寫的。
:)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-992014/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 特殊字元轉義Oracle字元
- mybatis 對特殊字元的模糊查詢MyBatis字元
- URL地址特殊字元轉換字元
- php過濾html標籤、特殊字元、轉義字元PHPHTML字元
- Shell命令列中的特殊字元及其轉義(去除特殊含義)命令列字元
- HTML 基礎知識(特殊字元的轉義)HTML字元
- Bash的特殊字元字元
- scheme跳轉特殊字元編碼問題Scheme字元
- 轉義正規表示式中特殊字元字元
- 文字中的特殊字元字元
- HTML特殊字元HTML字元
- 網址URL中特殊字元轉義編碼字元
- 查詢某欄位有特殊字元(PATINDEX函式)字元Index函式
- 【HTML】08特殊字元HTML字元
- Oracle 去特殊字元Oracle字元
- 如何去除特殊字元字元
- react 渲染 html 特殊字元的bugReactHTML字元
- HTML特殊字元顯示HTML字元
- perl替換特殊字元字元
- 特殊字元——反斜槓(\)字元
- 分享一個簡單的 laravel 應用健康檢查命令Laravel
- Spring - 配置檔案中的特殊字元Spring字元
- python如何刪除字串的特殊字元Python字串字元
- MySQL like查詢字元轉義遇到的坑MySql字元
- 簡單的查詢
- (問)get請求會對中文及特殊字元進行轉碼字元
- mongodb密碼特殊字元的解決方法MongoDB密碼字元
- 深入剖析go中字串的編碼問題——特殊字元的string怎麼轉byte?Go字串字元
- MySQL用LIKE特殊字元搜尋MySql字元
- 萬用字元與特殊符號字元符號
- Mac——如何輸入⌘、⌥、⇧、⌃、⎋等特殊字元Mac字元
- 如何在 Mac上插入特殊字元Mac字元
- 特殊字元關鍵字篩選字元
- 【陣列】1608. 特殊陣列的特徵值(簡單)陣列特徵
- Linux裡面去掉檔案特殊字元的命令Linux字元
- Linux系統中必須掌握的特殊字元!Linux字元
- Java String 去掉特殊字元之前的內容方法Java字元
- 簡單的查詢語法
- ptyon 特殊處理 url 編碼與解碼,字元編碼轉化 unicode字元Unicode