Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MaskEdit null value error 1

Status
Not open for further replies.

CritterLover

Programmer
Jul 21, 2003
19
0
0
US
I have a form that performs a search based upon various criteria. Multiple searches may be performed one right after another. It searches on name, social security number and / or date of birth. The date of birth is a TMaskEdit. It works fine if there is no data put into the DOB or if data IS put there. If a date is input and then removed, the whole search blows up with:
'...raised exception class EDBEditError with message 'Invalid input value. Use escape to to abandon changes'. Process stopped...'
The editmask is '!00/00/0000;1;_'
text is ' / / '
I have to be able to search on a DOB and then another criteria without exiting the form and reopening it.

I've tried creating a procedure:
procedure TFrmDVDataSrch.ValidateEdit(Sender: TObject);
but it never seems to get there. I haven't worked with methods yet so if that's involved I'd need really specific information on how to do that. I'm still pretty new to Delphi. What am I doing wrong? Any help is much appreciated!
 
In the OnExit event handler (Obj inspector in the IDE, Events tab, double-click in the blank box next to "OnExit") for your TMaskEdit, use something like this:

If MaskEdit1.Text = ' / / ' then
MaskEdit1.Clear;

(This assumes that the name of your component is "MaskEdit1" - change that to whatever the real name of your TMaskEdit is.)

This will clear the blank value from the Text.

-D
 
Probably the best advice is not to use TMaskEdit. It does seem to cause lots of problems.

However if you have to use it then use the Clear procedure to clear the data in the MaskEdit:
Code:
begin
  MaskEdit1.Clear;
end;
Of course, your user might simply select the data in the MaskEdit and press Delete or Backspace. In which case write an OnKeyDown event handler as follows:-
Code:
procedure TForm1.MaskEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key in [ VK_DELETE, VK_BACK ] then begin
    Med.Clear;
    key := 0;
  end;
end;


Andrew
Hampshire, UK
 
A typo in the event handler that I submitted. The line
Code:
  Med.Clear;
should of course be
Code:
  MaskEdit1.Clear;
Sorry.

Andrew
Hampshire, UK
 
I think it's the TMaskEdit that is blowing up, not the actual search.
If you don't want to try trapping the error (and I've not been able to), you might tolerate a button labelled "Clear Date" by the birth date field. If this calls MaskEdit1.Clear then that should fix the problem.
 
The error occurs BEFORE the OnExit or OnValidate events. There doesn't seem to be a good solution for this. Right now I'm doing a
EditMask1.clear;
after EACH search which works. Thanks for that info! However, if they delete the date prior to doing a search it won't catch that. I guess I'll put a 'Clear date' button there (yuk!) also. I could maybe use the delete / backspace OkKeyDown event, but if they use the mouse to highlight and delete the date, it wouldn't catch that either... I'll keep pluggin' away... At least this solves SOME of the conditions. I guess the 'Clear Date' button will be a new 'feature'. [ponder]

If I didn't use MaskEdit, then what else can I use to get the date formatting? (Like I said, I'm a newbie). Thanks!
 
What's wrong with the solution I suggested of having an OnKeyDown event handler which will trap the Del or Backspace key (and remove the keystroke) BEFORE it gets to the OnExit and OnValidate events?

This works for me and you don't need to have a Clear button.

Andrew
Hampshire, UK
 
Okay, it DOES catch the mouse movement, too. I thought it only caught it if you actually used the delete or backspace keystrokes. I stand corrected. Like I said, I'm pretty new to this. Thanks for your help and patience! That does exactly what I need!
 
Okay, it did work even with the mouse. I thought it would only work with the Delete and Backspace keystrokes, but not the mouse. That'll teach me!!! Like I said, I'm pretty new to this so I made an assumption before I fully tried it. That does EXACTLY what I need!! Thanks for your time and patience!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top