home *** CD-ROM | disk | FTP | other *** search
- unit RFEdit;
- {Implementation of a TEdit component with
- filter and required field validation }
- {Copyright (c), 1995 by Wm. Romano. All Rights Reserved}
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TValidChar=String;
- TRFilterEdit = class(TEdit)
- private
- { Private declarations }
- protected
- FRequired : Boolean;
- FValidch : TValidChar;
- ValidChar : set of char;
- { Protected declarations }
- Procedure SetValidCh(Value:TValidChar);
- Procedure SetRequired(Value:Boolean);
- public
- { Public declarations }
- Constructor Create(AOwner:TComponent); override;
- procedure KeyPress(var Key: Char); override;
- Procedure DoExit; override;
- published
- { Published declarations }
- Property ValidChars:TValidChar
- read FValidCh
- Write SetValidCh;
- Property RequiredField:Boolean read FRequired
- write SetRequired;
- end;
-
- procedure Register;
-
- implementation
- Constructor TRFilterEdit.Create(AOwner:TComponent);
- begin
- inherited Create(AOwner);
- FValidCh:='[]';
- FRequired:=False;
- end;
- Procedure TRFilterEdit.SetRequired(Value:Boolean);
- Begin
- if Value<>FRequired then
- FRequired:=Value;
- end;
-
- procedure TRFilterEdit.DoExit;
- begin
- inherited DoExit;
- if FRequired then
- begin
- if Text = '' then
- Begin
- MessageDlg(' Field is required! ',mtWarning, [mbOK],0);
- SetFocus;
- end;
- end;
- end ;
-
-
-
-
- Procedure TRFilterEdit.SetValidCh(Value:TValidChar);
- var
- vc3 : set of char;
- x : integer;
- ch1,ch2,ch3 : char;
- SetRange : boolean;
-
- Procedure MakeSet;
- Begin
- if SetRange then vc3:=[ch1..ch2]
- else
- vc3:=[ch1];
- validchar:=validchar+vc3;
- ch1:=#0;ch2:=#0;ch3:=#0;
- SetRange:=False;
- End;
-
- Begin {SetValidCh}
- SetRange:=False;
- if Value<>FValidCh then
- BEGIN
- FValidCh:=Value;
- if (FValidCh[1]='[') and
- (FValidCh[length(FValidCh)]=']' )then
- For x:=2 to length(FValidCh) do
- begin
- ch3:=FValidCh[x];
- if (ch3=',') or (ch3=']') then
- begin
- MakeSet;
- end;
- if ch3='.' then SetRange:=True;
- if ch3='''' then
- begin
- ch3:=FValidCh[x+1];
- x:=x+2;
- end;
- if (SetRange=False) then ch1:=ch3
- else ch2:=ch3;
- end
- else
- FValidCh:='Invalid Format '+ FValidCh;
- end;
- end;
-
- procedure TRFilterEdit.KeyPress(Var Key: Char);
- begin
- if ValidChar <>[] then
- if (NOT (Key in ValidChar))
- and (Key<>#08) then Key:=#0;
- inherited KeyPress(Key);
- end;
-
- procedure Register;
- begin
- RegisterComponents('Additional', [TRFilterEdit]);
- end;
-
- end.
-