Closed Thread
Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: How do you validate an ADOtable?

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    How do you validate an ADOtable?

    So I have an ADOtable linked to my database. I can freely enter data in the fields, and I want to validate them.

    What do I do to validate it? Usually when I validate a edit box, I use the OnkeyPress Event. But here, it can be any field..how would I find out which field it is in?

    Would I say something like:

    case Keypress.field of

    Blah:
    begin
    validation
    end;

    blah2
    begin
    validation
    end;

    ?

    Since I have different validations for each field. Can someone confirm, thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How do you validate an ADOtable?

    I wouldn't directly expose an ADOTable in your forum. Do the validation in the interface to it.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do you validate an ADOtable?

    Come again? Sorry, I don't understand what you mean, laymen terms please >__>

  5. #4
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: How do you validate an ADOtable?

    You can use the same event code for multiple controls. The "Sender" parameter is a pointer to the control that triggered the event.

    If you have a OnKeyPress event for numbers, you can reuse the event for all TEdit controls that accept numbers.

    I would also look into TMaskEdit and JEDI's TJvDBSpinEdit which handles validation for you.

  6. #5
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: How do you validate an ADOtable?

    Yes. May I add that it doesn't seem to make much sense to have 1 handler for all your edits and then handle them separately anyway inside that one handler?
    Instead, give each edit its own handler!

    Ps, to test the Sender use
    Code:
    If Sender=DBEdit1 then //cannot use case with pointers :)
     begin
      ...ValidateThis...;
       exit; //optional, uness you have a "default". Like this, your handler is left immediately
     end;
    This assumes the edit you want to test is DBEdit1, but you can change that. You can also put more.
    Whatever you like, I guess.

  7. #6
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do you validate an ADOtable?

    0_o, sorry but I am only still A level standard >__>

    I think I didnt describe the problem properly. I have a table and each column has its own validation, Ie, Postcode has string, and telephone number has only integers.

    But they are part of the same DBGrid, so I was wondering how I would have each validation for each.

    But, I figured a different method. Is it possible to have a situation where:

    You select a row in the DBgrid to edit,

    then I also have a combobox elsewhere on the form with all the header titles of the columns. Next to this I have a Editbox where I can change the field to whatever I want.

    So I highlight the row, choose the column to edit, then type in the edit box, then click Ok. I'm gonna make the DBgrid read only, so nothing can be changed directly. This is possible right?

    Or should I do it another more efficient method?

    Thanks

  8. #7
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: How do you validate an ADOtable?

    Well, you could probable use a case then, based on a column index, but I am not very familiar with those DBGrid things. Good luck with it .

  9. #8
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: How do you validate an ADOtable?

    O, right. Gotcha. look into OnBeforePost

    An application might use BeforePost to perform validity checks on data changes before committing them. If it encountered a validity problem, it could call Abort to cancel the Post operation (Delphi) or throw an exception (C++).
    Code:
    procedure TFormMain.TableBeforePost(DataSet: TDataSet);
    begin
      with DataSet.FieldByName('N1') do
        if (Value < 1000) or (Value > 9999) then
          raise Exception.Create(FieldName + ' is invalid');
    
      with DataSet.FieldByName('N2') do
        if (Value < 0) or (Value > 100) then
          raise Exception.Create(FieldName + ' is invalid');
    end;
    Using this method will prevent any control from posting invalid data to the table. Also look into database validation. Most databases will have some kinda extended validation.

    ie: Access has validation rules. Paradox (BDE) has some basic validation checks (min, max, masking). MySQL has even more.
    Buzz PHP Class Library - Web Components Made Easy!
    http://www.buzzphp.com/

  10. #9
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: How do you validate an ADOtable?

    I do not have Onbeforepost on my DBgrid Events list :S I tried checking on google, but I can't find anything on it apart from some high level computing >__>

  11. #10
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: How do you validate an ADOtable?

    Buzz PHP Class Library - Web Components Made Easy!
    http://www.buzzphp.com/

Closed Thread
Page 1 of 4 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Validation - How can I validate a form with PHP
    By John Ugwuozor in forum PHP Development
    Replies: 2
    Last Post: 08-04-2010, 10:20 AM
  2. javascript function to validate
    By edwin namisi in forum JavaScript and CSS
    Replies: 2
    Last Post: 05-19-2010, 04:43 PM
  3. Replies: 0
    Last Post: 03-29-2010, 03:29 PM
  4. ADotable Trivial Question
    By 2710 in forum Pascal and Delphi
    Replies: 3
    Last Post: 02-16-2010, 02:39 PM
  5. How to validate prospects?
    By BAII in forum General Programming
    Replies: 2
    Last Post: 05-05-2008, 12:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts