在TCustomMaskEdit控件下继承一个新的类,重载它的ValidateError方法,自己写提示或处理!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask;
type
TMyMaskEdit=Class(TCustomMaskEdit)
protected
procedure ValidateError; Override;
end;
TForm1 = class(TForm)
MaskEdit1: TMaskEdit;
procedure FormCreate(Sender: TObject);
private
MaskEdit2: TMyMaskEdit;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyMaskEdit }
procedure TMyMaskEdit.ValidateError;
begin
MessageBeep(0);
ShowMessage('My self error message!');
//或者你干脆把错误提示字符串写成一个属性,在此调用显示这个属性,这样就可以自定义每个控件的不同提示.
Abort;//最好有这句,可以中止操作比如Exit.
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MaskEdit2:=TMyMaskEdit.Create(Self);
MaskEdit2.Parent:=Self;
MaskEdit2.EditMask:=MaskEdit1.EditMask;
end;
end.