You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何检测TAdvColumnGrid单元格值变化并触发声音告警?

问题求助:TAdvColumnGrid单元格值变化触发声音告警

我是刚入行的新手,这个问题看似简单,但查阅大量资料仍未解决。

我正在开发一个简单的监控系统,目前仅剩该功能未完成:当TAdvColumnGrid(替代StringGrid的组件)的单元格值变化时(数据来自Oracle数据库,每5分钟重新加载),通过声音通知用户。我已有播放声音的代码。

表格结构如下:

Header AHeader BHeader C
A Data80%Good
B Data60%Warning

我希望基于Header C列实现告警,当值变为Warning时触发声音。

请问该如何实现?是否有我不知道的过程或函数?若问题表述不当或信息不足,请告知。


初始代码

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;  

更新后代码

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;    

内容的提问来源于stack exchange,提问作者Tae Ung Yun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 11:54:04