Problems with adoTable

I would like to be sure that if the table (in this case adotHours ) enters edit or paste mode and the user clicks the save button, but accidentally places the same value in the Hours column, as the message Please enter another value has already appeared, otherwise, if the user enters a different value, a different piece of code is used.

I tried the following method, but it does not work - no matter what the user enters the message Please enter another value .

 procedure TfrmLabour.Button6Click(Sender: TObject); var i,j, t: String; begin Edit1.Text := adotHours['Hours']; j := Edit1.Text; adotHours.Post; Edit2.Text := adotHours['Hours']; t := Edit2.Text; if t = j then showmessage ('Please enter another value') else begin..... end; 

while I know that this is not the most elegant code, I thought that after the value was sent to adotHours Hours via the connected DBgrid , if it was a different value before t would become the new value and therefore adotHours['Hours'] will be different and allow else begin . Suggestions?

+4
source share
3 answers

Try checking the entered value on the OldValue property.

 adotHours.FieldByName('Hours').OldValue 
+7
source

adotHours.FieldByName('Hours').NewValue will be Unassigned if the field value does not change. In this case, OldValue will contain a (unmodified) value.

+2
source

You can use something like this:

 if adotHours.FieldByName('ItemName').OldValue = adotHours.FieldByName('ItemName').Value then Showmessage(Please enter another value'); 

But for me it would be better to put this code in the adotHours.BeforePost event and call the abort procedure, if the values ​​are the same - in another case, when the user changes the value and clicks on another line on the grid - it calls the publication in the data set, and you can skip check button.

0
source

Source: https://habr.com/ru/post/1403755/


All Articles