Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 1 of 1 total
Thread Extending TEdit to implement validation base on RegEx
Mon, Jun 17 2019 1:42 PMPermanent Link

Mario Enríquez

Open Consult

Hi Folks,

I need to extend TEdit to include some properties and a method to support input validation base on RegEx.

The idea is to have a Validation string property where one can enter a RegEx expression to validate the value on the Text property and a method that returns True/False whatever the Text property pass the validation or not.

This is the basic functionality that I expect to achieve, and plan to extend it to a more robust validation schema where on can ask the parent/owner to check for validation of all its members before submiting a form.

The thing is, I'm stuck in the implementation..

For some reason, when the Text property is assigned that Text property in the Embbed TEdit is not getting updated.

Any idea or recommendations?

I've extentd TEdit the following way:


  TmkEdit = class(TEdit)
        { Private declarations }
        FValidationExpStr: string;
        FIsRequired: boolean;

        FEdit : TEdit;

//         function GetInputType
//         procedure SetInputType default tiNone

        { Protected declarations }
        function DoGetText: String; override;
        procedure DoSetText(const Value: String); override;
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
        function isValid: boolean;
        { Published declarations }
        property Top;
        property Left;
        property Height;
        property Width;
        property Alignment;
        property AlwaysOnTop;
        property Animations;
        property AutoComplete;
        property Constraints;
        property Cursor;
        property DataColumn;
        property DataSet;
        property Direction;
        property DisplayOrder;
        property Enabled;
        property Font;
        property Hint;
//         property InputType: TTextInputType read GetInputType write SetInputType default tiNone
//            description 'Specifies the input type (useful for mobile so that the proper keyboard is shown)';
        property Layout;                    
        property LayoutOrder;
        property Margins;
        property MaxLength;
        property ReadOnly;
        property SpellCheck;       
        property TabOrder;
        property TabStop default True;
        property Tag;
        property Text: string read DoGetText write DoSetText;
        property Visible;
        property ValidationExpression: string read FValidationExpStr write FValidationExpStr;
        property IsRequired: boolean read FIsRequired write FIsRequired;
        property OnAnimationComplete;
        property OnAnimationsComplete;
        property OnShow;
        property OnHide;
        property OnMove;
        property OnSize;
        property OnClick;
        property OnDblClick;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnMouseEnter;
        property OnMouseLeave;
        property OnTouchStart;
        property OnTouchMove;
        property OnTouchEnd;
        property OnTouchCancel;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnChange;


uses WebForms, WebDesign;
uses WebForms, WebDOM;

constructor TmkEdit.Create(AOwner: TComponent);
  inherited Create(AOwner);

  FEdit := TEdit.Create(Self);
  FEdit.Top := Top;
  FEdit.Parent := Self;

  FEdit.Margins.Bottom := 0;
  FEdit.Margins.Left := 0;
  FEdit.Margins.Right := 0;
  FEdit.Margins.Top := 0;

  FEdit.LayOut.Position := lpLeft;
  FEdit.LayOut.Consumption := lcNone;
  FEdit.LayOut.Overflow := loRight;

function TmkEdit.DoGetText: String;
  Result := FEdit.Text;

procedure TmkEdit.DoSetText(const Value: String);
  FEdit.Text := Value;