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
I wouldn't directly expose an ADOTable in your forum. Do the validation in the interface to it.
Come again? Sorry, I don't understand what you mean, laymen terms please >__>
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.
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
This assumes the edit you want to test is DBEdit1, but you can change that. You can also put more.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;
Whatever you like, I guess.
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![]()
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.
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++).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.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;
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/
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 >__>
Its in TDataSet so it will be in your TADOTable.
Delphi OnBeforePost - Google Search
http://docwiki.embarcadero.com/CodeS...rePost_(Delphi)
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks