Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems with adoTable

i would like to be able to ensure that if a table (in this case adotHours) enters Edit or insert mode and the user clicks the save button but accidentally posts the same value under the Hours column as was already entered, a message appears Please enter another value, otherwise if the user enters a different value, another piece of code is used.

I have tried the following method but it doesn't work,- whatever the user enters the message Please enter another value appears.

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 it may not be the most elegant code, my thinking was that once the value had been posted to adotHours Hours through the connected DBgrid, if it was a different value to before t would become the new value and therefore adotHours['Hours'] would be different and allow the else begin. Suggestions?

like image 503
Jeowkes Avatar asked Jan 17 '23 01:01

Jeowkes


2 Answers

Try checking the entered value against the OldValue property.

adotHours.FieldByName('Hours').OldValue
like image 185
RRUZ Avatar answered Jan 22 '23 21:01

RRUZ


adotHours.FieldByName('Hours').NewValue will be Unassigned if the field value is not modified. In that case, OldValue will contain the (unmodified) value.

like image 36
GolezTrol Avatar answered Jan 22 '23 22:01

GolezTrol