This is a very simple component, and it is also very simple to write it. It is to solve the special character check problem when data is entered. At the beginning, you should write a function implementation, but feel troubles, later think of writing a simple VCL to traverse all the components on the Form. This VCL is currently just checking all TEDIT and TCOMBOX components, interested friends can expand their own.
I think this VCL is still a little help for those who write database programs, such as Check for single quotes.
If you want to check what symbol is set, you will automatically check if you set a check function when you set it in the property.
Another role of it is to be a simple entry routine written by writing VCLs.
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;
PROCEDURE register;
IMPLEMENTATION
Procedure Register; Begin RegisterComponents ('MyVCl', [Tsymbolchecker]); END;
Constructor Tsymbolchecker.create (Aowner: Tcomponent); Begin Inherited Create (Aowner); CheckControls: = [ctedit, ctcomboBox];
{Set Property Active Value} Procedure Tsymbolchecker.setACTIVE (Value: Boolean); Begin IF Value = Factive Then EXIT; FACTIVE: = VALUE;
{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 the EXIT; fCheckstring: = value; if trim (fcheckstring) = '' TENSETAACTIVE (FALSE);
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) 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) THEN BEGIN for J: = 1 To Length (Trim (fcheckstring)) Do Begin if Pos (MIDSTR (Trim) String), J, 1), TcomboBox (Owner.components [I]). Text)> 0 The begin ShowMessage ('Error Symbol!'); Tcombobox (Owner.components [i]). Setfocus; exit; end; ; End; end; end; end; end.
Finally, it will be explained that it is written with delphi6.
:)