I've found a way to do it by reading through the DBGrid and comparing the new value to the old value (see below), but what I would also like to do is change the colour on the changed field to green if the called procedure returns with 'Success' or red if it is 'Failed', but only once I have read the row and processed it. At the moment I am building a Stringgrid in line with the DBGrid as I read it to show the text 'Updated', 'Failed' or 'Not changed' based on the results.
To check for changed values I am using the following:-
DBGrid1.DataSource.DataSet.DisableControls;
for Rcount := 1 to dbgrid1.datasource.dataset.RecordCount do
begin
count := count + 1;
dbgrid1.datasource.dataset.RecNo:=Rcount;
// if SNP value has changed
if DBGrid1.DataSource.DataSet.Fields[2].NewValue <>
DBGrid1.DataSource.DataSet.Fields[2].oldValue then
begin
// Call the stored procedure to update the SNP
srf:=DBGrid1.DataSource.DataSet.Fields[0].AsString;
sqb:=DBGrid1.DataSource.DataSet.Fields[1].AsString;
snp:=DBGrid1.DataSource.DataSet.Fields[2].AsString;
ReturnStatus:=' ';
ChangeSNP(srf, sqb, snp, ReturnStatus);
// Populate the StringGrid to show the updated rows
if DBGrid1.DataSource.DataSet.Fields[2].NewValue <>
DBGrid1.DataSource.DataSet.Fields[2].oldValue then
begin
Form2.Label5.caption:='Changing colours';
StringGrid1.cells[0, RCount]:='Updated';
StringGrid1.canvas.Brush.color:=clGreen;
end
else
begin
StringGrid1.canvas.Brush.color:=clRed;
StringGrid1.cells[0, RCount]:='Failed';
end;
end;
if DBGrid1.DataSource.DataSet.Fields[2].NewValue =
DBGrid1.DataSource.DataSet.Fields[2].oldValue then
begin
StringGrid1.cells[0, RCount]:='Unchanged';
end;
end;
DBGrid1.DataSource.DataSet.EnableControls;