TEdit with Validate. Impossible? lazarus / 7-LCL ---------------------------------------------------------------------- mmustaros · 2006-07-21 22:10 TEdit with Validate. This is a recurrent request, I've seen it for years in many forums and for distincts languges, and I never found a satisfactory answer. I think that must exist a component derived from TEdit with the following methods. procedure OnEnter(Sender: TObject); procedure OnValidate(Sender: TObject; var Ok: Boolean); procedure OnExit(Sender: TObject); In OnEnter Procedure, we must have a System property, which let us know if the focus is entering in this procedure caused for focus movement, or it's for re-entering after minimizing the Form or hideing it, when it recover the focus. OnValidate Procedure, must be executed always that we do click on other object, or we press Tab, Back-Tab, Esc or Return (keys of focus movement). If we return inside this procedure the Ok variable to False, not OnEnter, OnExit, Click, etc. must be executed on this or other objects. TEdit must Delete all the events pending in the Events- Queue. OnExit Procedure, of course, will be executed after OnValidate (if exist) and just before lost focus for Focus change of object, it may not execute for minimizing or hideing the Form. If we can have this component with this use, for example we can change the color to green, when it receives the Focus, if there is an Error, We can show a message and the TEdit will continuing in green. Finally when the error will be correct and the user change the focus to other object, in the OnExit, we restore the initial color of it. it will be marvellous. There is in Delphi a link from Borland http://bdn.borland.com/article/0,1410,16171,00.html about this, but it doesn't work with Lazarus. Please I'd like to know your opinion. Thanks. Miquel mmustaros@hotmail.com ---------------------------------------------------------------------- felipemdc · 2006-11-23 16:29 Sure, go ahead and implement it =) If you can release under modifyed LGPL on the Lazarus Code and Components Repository, much better =) ---------------------------------------------------------------------- lfrodrigues · 2006-11-28 02:07 I Have something like that. An TEdit that does validation. Where/to whom should I send it? ---------------------------------------------------------------------- Marc · 2006-11-28 16:36 1) Be carefull when validating in an OnExit handler. Before you know you end up in a validation looop you cannot exit. (Imagine what happens when you focussed to another edit which is also invalid) 2) restoring from minimize should not trigger a refocus IMO. 3) Bypassing events since something is not OK is unwanted IMO (and hard to implent cross platform). Also I'm not sure of the enter/leave order ---------------------------------------------------------------------- lfrodrigues · 2006-11-28 20:22 I don't use events, I use KeyPress events to check the letter. Code: [Select] procedure TNumEdit.KeyPress(var Key: Char); var   S: String; begin   if (FStyle in [esNumber, esPosNumber]) then   begin     if not (Key in ['0'..'9','-',DecimalChar,#8]) then Key := #0     else     begin        S := Text;        Delete(S, SelStart+1, SelLength);        if FStyle = esPosNumber then        begin          if Key = '-' then Key := #0;          if (Key = DecimalChar) and (Pos(Key,S) > 0) then Key := #0;        end        else          if (Key in [DecimalChar,'-']) and (Pos(Key,S) > 0) then Key := #0;     end;   end   else if (FStyle = esNoSpace) then   begin     if (Key = ' ') then Key := #0;   end;   inherited KeyPress(Key); end; Is anyone interested in the full component? to whom should I sumit the code. best regards ---------------------------------------------------------------------- Zorba · 2006-11-29 04:00 Quote from: "lfrodrigues"Is anyone interested in the full component? to whom should I sumit the code. best regards I think the more working components the better. That goes for code and examples as well. As a user of Lazarus I thank you in advance. To submit your component Check the wiki admin email. ---------------------------------------------------------------------- Vincent Snijders · 2006-11-29 07:59 See wiki on how to release a component. ---------------------------------------------------------------------- Marc · 2006-11-29 10:32 Quote from: "lfrodrigues"I don't use events, I use KeyPress events to check the letter. Isn't that a contradiction ? And what if I cut&pasted some numbers ? ---------------------------------------------------------------------- lfrodrigues · 2006-11-29 19:11 Quote from: "Marc"I don't use events, I use KeyPress events to check the letter. Isn't that a contradiction ? I wanted to say I didn't use special events... Quote from: "Marc" And what if I cut&pasted some numbers ? Ups I forgot that. I will rewrite it an submit it. Thanks ---------------------------------------------------------------------- Marc · 2006-11-30 10:38 Keep in mind that there are more way to enter "text" than you and I can think of. In general, filtering keystrokes is a bad idea. What about IME input ? What about input by special devices for disabled people ? The only solution I've found this far (I've been dealing with this for years) is validating the input, the moment a user presses OK. Depending on the case, show a nice dialog, color the label/text, mark the label, show some icon/bullit/whatever next to the incorrect input. ---------------------------------------------------------------------- lfrodrigues · 2006-12-03 17:28 Yep, You're right. I really have thought about IME input... Thanks