1

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;    
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • If you are using `TAdvColumnGrid` then you most probably are filling the grid manually. So either play the sound where you fill it or use one of the `On_x_Change(d)` events. If you did try this then please show your code attempting it – Blurry Sterk Jul 21 '22 at 06:32
  • Why are you not using any DB-aware grid component? So you would not have to fill the grid yourself! – Delphi Coder Jul 21 '22 at 07:37
  • 1
    @DelphiCoder because My boss wants to do that, I don't know why he prefer column grid components rather than DBGrid – Tae Ung Yun Jul 21 '22 at 07:45
  • @BlurrySterk I'm not sure This is right way show my code. I try to use comment but that code is quiet long so I Edit my post. – Tae Ung Yun Jul 21 '22 at 08:04
  • @TaeUngYun - Some StackOverflow users would add a heading like `Update` or `Edit` or something similar to their question above the additions, in your case the code you added – Blurry Sterk Jul 21 '22 at 08:53
  • I suspect you would have a loop in which you would add each record's data to the grid which you do not show here. Your example above will bring up many questions from the guys on SO. Try and make it be working code in the very least in your question. Considering that you might have a loop here I would suggest that you do not play the sound on each occurance of the warning in the loop but only once after the loop if you had at least 1 occurance – Blurry Sterk Jul 21 '22 at 08:56
  • @BlurrySterk I'm so sorry about my ignorance this is my first time using Stackoverflow so I'm not used to it. I added fully functional code. you mean I should put that 3 lines between `end;` and `Result := RETURN_SUCCESS` am I Correct? – Tae Ung Yun Jul 21 '22 at 10:21
  • 1
    Let me give you a hint; While you are filling the grid with the records from the DB and with the current state of your code you might be playing the sound multiple times... one per each warning you encounter. That is wasteful and the idea is to only play it once irrespective of how many warnings you encounter while filling the grid. I am sure you can figure out how to fix that. :D – Blurry Sterk Jul 21 '22 at 10:31
  • Then ask your boss to explain it to you in detail, what he thinks are the advantages of it. Just a small hint, TMS also (a) has DB-aware grid(s). – Delphi Coder Jul 21 '22 at 11:08

0 Answers0