How can I detect when a StringGrid cell value has changed?

271 views Asked by At

I am a noob who just entered this field. I know this question seems stupid, but please understand, I tried to look up a lot of info to solve this problem but failed.

What I want to make is a simple Monitoring System, and it is almost done except for this feature.

I want to notify the user by sound when a StringGrid cell value has changed (the value is coming from an Oracle database, and it is reloaded every 5 minutes).

I already have code about how to play a sound.

The grid looks like this:

header A header B header C
A Data 80% Good
B Data 60% Warning

I want to make an alert based on header C, when a value goes to Warning.

In this case, how can I make this thing work?

Is there any procedure or function that I don't know about?

I desperately need your help. Please give me guidelines or advice.

If my question is inappropriate, or lack of information, then please let me know.

PS: I use TAdvColumnGrid components.

PS:

S := S + 'My Query goes on' + #13#10;  
try  
  TUniQuery.SQL.Clear;  
  TUniQuery.SQL.Text := S;  
  TUniQuery.Open;  
  if not TUniQuery.IsEmpty then begin  
    Grid.RowCount := Grid.FixedRows + TUniQuery.RecordCount;  
    R := Grid.FixedRows + TUniQuery.RecNo - 1;  
    F := Q.FieldByName('Header A');  
    Grid.Cells[GRID_C_HEADER_A, R] := F.AsString;  
    F := Q.FieldByName('Header B');  
    Grid.Cells[GRID_C_HEADER_B, R] := F.AsString;  
    F := Q.FieldByName('HEADER_C');  
    Grid.Cells[GRID_C_HEADER_C, R] := F.AsString;  
    if Grid.Cells[GRID_C_HEADER_C, R] = 'Warning' then begin  
      PlaySound(PLAY_SOUND_WARNING)  
  end;   // these 3 lines are added by sterk's advice
end;  

Update:

S := S + 'My Query goes on' + #13#10;
Q := TUniQuery.Create(Self);
Q.Connection := TEST_DB.dbConnection;
Q.SpecificOptions.Values['FetchAll'] := 'True';
try
  Q.SQL.Clear;
  Q.SQL.Text := S;
  Q.Open;
  if not Q.IsEmpty then begin
    Grid.RowCount := Grid.FixedRows + Q.RecordCount;
    while not Q.EoF do begin
      R := Grid.FixedRows + TUniQuery.RecNo - 1;
      F := Q.FieldByName('Header A');
      Grid.Cells[GRID_C_HEADER_A, R] := F.AsString;
      F := Q.FieldByName('Header B');
      Grid.Cells[GRID_C_HEADER_B, R] := F.AsString;
      F := Q.FieldByName('HEADER_C');
      Grid.Cells[GRID_C_HEADER_C, R] := F.AsString;
      if Grid.Cells[GRID_C_HEADER_C, R] = 'Warning' then begin
        PlaySound(PLAY_SOUND_WARNING)
      end;
      Q.Next;
    end;
    Result := RETURN_SUCCESS;
  end;
end;    
0

There are 0 answers