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?
Try checking the entered value against the OldValue property.
adotHours.FieldByName('Hours').OldValue
adotHours.FieldByName('Hours').NewValue will be Unassigned if the field value is not modified. In that case, OldValue will contain the (unmodified) value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With