1
votes

I need advice about the following situation. These are my design settings:

object cdsMonitor: TClientDataSet
  Active = True
  …
  object cdsMonitorSendReceive: TBooleanField
    FieldName = 'SendReceive'
  end
  object cdsMonitorMessage: TStringField
    FieldName = 'Message'
  end
  object cdsMonitorTime: TTimeField
    FieldName = 'Time'
  end
end

object dsMonitor: TDataSource
  DataSet = cdsMonitor
  …
end

object dbgMonitor: TDBGrid
  …  
  DataSource = dsMonitor
  …
end

I am adding data to the dataset with the following code:

cdsMonitor.Append;
cdsMonitorSendReceive.Value := False;
cdsMonitorMessage.Value := Bytes;
cdsMonitorTime.Value := Now;
cdsMonitor.Post;

In the application source there is a function that executes the above block of code several times (in a loop). The problem is that I don’t see the appended rows appearing one by one but for several seconds I don’t see anything (the function is time consuming) and then all the appended rows appear simultaneously. I want to see the result not only when the code execution has finished but I want the DBGrid to be refreshed after each appended row so that I can watch the progress in real time. I can achieve this by adding

Application.ProcessMessages;

to the above block of code. However this interferes with the normal flow of code execution because not only the grid is updated but other messages are processed as well which is not desirable. So this is not the solution I am looking for. Any other ideas?

1
YourGrid.DataSource.DataSet.Refresh wouldn't help ? [just a guess] - TLama
Have you tried replacing your Application.ProcessMessages by calls to cdsMonitor.DisableControls and cdsMonitor.EnableControls surrounding your loop? It won't show the intermediate updates but should be noticeably quicker than without. - MartynA
@TLama, No, Refresh doesn't work. - Rick77
@moskito-x Yes, I saw it but I didn't have the chance to try it until now. Thanks! This is exactly what I was looking for! - Rick77
@Rick77 : Good to know it works. Thx :-) - moskito-x

1 Answers

1
votes

You can do a dbgMonitor.Repaint;

cdsMonitor.Append;
cdsMonitorSendReceive.Value := False;
cdsMonitorMessage.Value := Bytes;
cdsMonitorTime.Value := Now;
cdsMonitor.Post;
dbgMonitor.Repaint;

That will do what you want to achieve