Recent

Author Topic: TEdit with Validate. Impossible?  (Read 14921 times)

mmustaros

  • Newbie
  • Posts: 6
TEdit with Validate. Impossible?
« on: July 22, 2006, 12:10:40 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: TEdit with Validate. Impossible?
« Reply #1 on: November 23, 2006, 05:29:38 pm »
Sure, go ahead and implement it =) If you can release under modifyed LGPL on the Lazarus Code and Components Repository, much better =)

lfrodrigues

  • New Member
  • *
  • Posts: 25
RE: TEdit with Validate. Impossible?
« Reply #2 on: November 28, 2006, 03:07:34 am »
I Have something like that.

An TEdit that does validation.

Where/to whom should I send it?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
RE: TEdit with Validate. Impossible?
« Reply #3 on: November 28, 2006, 05:36:38 pm »
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
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

lfrodrigues

  • New Member
  • *
  • Posts: 25
RE: TEdit with Validate. Impossible?
« Reply #4 on: November 28, 2006, 09:22:57 pm »
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

  • Jr. Member
  • **
  • Posts: 77
Re: RE: TEdit with Validate. Impossible?
« Reply #5 on: November 29, 2006, 05:00:24 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Re: RE: TEdit with Validate. Impossible?
« Reply #6 on: November 29, 2006, 08:59:03 am »
See wiki on how to release a component.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: RE: TEdit with Validate. Impossible?
« Reply #7 on: November 29, 2006, 11:32:33 am »
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 ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

lfrodrigues

  • New Member
  • *
  • Posts: 25
Re: RE: TEdit with Validate. Impossible?
« Reply #8 on: November 29, 2006, 08:11:12 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
RE: Re: RE: TEdit with Validate. Impossible?
« Reply #9 on: November 30, 2006, 11:38:13 am »
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.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

lfrodrigues

  • New Member
  • *
  • Posts: 25
RE: Re: RE: TEdit with Validate. Impossible?
« Reply #10 on: December 03, 2006, 06:28:14 pm »
Yep, You're right.

I really have thought about IME input...

Thanks

 

TinyPortal © 2005-2018