Board index » delphi » Validation - OnValidate, Page controls, grids.. (oh my head hurts)

Validation - OnValidate, Page controls, grids.. (oh my head hurts)

Hi,

   I've got two problems - suggestions would be welcomed on either of
them ;-)

1) I'm trying to validate edits (both TEdit and TDBEdit), using OnExit
and OnValidate as appropriate, but having problems when the user changes
the visible tab on a PageControl.  

   As suggested in Borland's "Validating TEdits" TI, I'm requesting a
validation to occur via a windows message, in the OnExit event.  I then
have to move back to the original tab sheet, which by this time has been
hidden by the tab sheet the user had selected.  This means that the user
has to sit through multiple tab changes - taking several seconds -
before focus finally returns to the TEdit.

   Has anyone got any better ideas? ;-)

2) Has anyone else had problems with using OnValidate when editing
fields via a DBGrid?  I'm raising an exception, but the DBEdit doesn't
return focus to the suspect cell, and all mouse clicks generate the
exception again.  Keyboard controls still work as expected - eg, the
user can type ESC or type into the edit.

                                                      Cheers!

                                                      -Mike

--
 -----------------------------------------------------------------------
 Michael Marsden   mikem...@satan.demon.co.uk        mikem...@webcom.com
                   Home page - http://www.webcom.com/mikemars/index.html
                   Delphi - http://www.webcom.com/mikemars/mikedelf.html

 

Re:Validation - OnValidate, Page controls, grids.. (oh my head hurts)


Mike:

regarding #1:  I believe you are asking for a way to handle it when someone
changes the page on a tabbed notebook.  Basically, you want to call some edits
at that point, then only allow the change if the data passes the edits.  If
that is what you want, the answer is simple.

On the events panel of the object inspector for the tabbed notbook, click on
the "onchange" event.  Include your edit calls in this procedure.  Note that
the header allows you to return a value for "allowchange".  If the data fails
the edit, set allowchange to false, and the user will not be able to change
pages but instead will be returned to the original page.

I haven't any great idea on #2.  I usually do my validates using the on field
exit event so I detect the error as soon as it is made.

-Dave

Quote
>Hi,
>   I've got two problems - suggestions would be welcomed on either of
>them ;-)
>1) I'm trying to validate edits (both TEdit and TDBEdit), using OnExit
>and OnValidate as appropriate, but having problems when the user changes
>the visible tab on a PageControl.  
>   As suggested in Borland's "Validating TEdits" TI, I'm requesting a
>validation to occur via a windows message, in the OnExit event.  I then
>have to move back to the original tab sheet, which by this time has been
>hidden by the tab sheet the user had selected.  This means that the user
>has to sit through multiple tab changes - taking several seconds -
>before focus finally returns to the TEdit.
>   Has anyone got any better ideas? ;-)
>2) Has anyone else had problems with using OnValidate when editing
>fields via a DBGrid?  I'm raising an exception, but the DBEdit doesn't
>return focus to the suspect cell, and all mouse clicks generate the
>exception again.  Keyboard controls still work as expected - eg, the
>user can type ESC or type into the edit.
>                                                      Cheers!
>                                                      -Mike
>--
> -----------------------------------------------------------------------
> Michael Marsden   mikem...@satan.demon.co.uk        mikem...@webcom.com
>                   Home page - http://www.webcom.com/mikemars/index.html
>                   Delphi - http://www.webcom.com/mikemars/mikedelf.html

<><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Dave Krajcar
Before Oct 30:  krajc...@ohsu.edu; after Oct 30:  rai...@pacifier.com

Re:Validation - OnValidate, Page controls, grids.. (oh my head hurts)


Quote
mikemars wrote:

> Hi,

>    I've got two problems - suggestions would be welcomed on either of
> them ;-)

> 1) I'm trying to validate edits (both TEdit and TDBEdit), using OnExit
> and OnValidate as appropriate, but having problems when the user changes
> the visible tab on a PageControl.

Try calling the UpdateRecord Method of your field's dataset in the
TabbedNotebook's OnChange Event.  This should force the ONvalidate
events to be called at that point.  You might have to keep a global flag
somewhere to detect that the record is valid and only allow the Tab
change if it is.  On the other hand, maybe raising an exception in the
OnValidate event will do the trick automatically.

Quote

> 2) Has anyone else had problems with using OnValidate when editing
> fields via a DBGrid?  I'm raising an exception, but the DBEdit doesn't
> return focus to the suspect cell, and all mouse clicks generate the
> exception again.  Keyboard controls still work as expected - eg, the
> user can type ESC or type into the edit.

Don't know about that one, sorry.

Alain Toutant
a.tout...@sympatico.ca

Other Threads