Recent

Author Topic: [Solved] ComboBox and OnChange-event  (Read 3087 times)

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] ComboBox and OnChange-event
« on: February 09, 2019, 01:22:29 pm »
I am working with Lazarus 2.0.0 on Mac OsX High Sierra.
The on change-event isn't being activated.


Is this a know issue or am i doing something wrong?
« Last Edit: February 11, 2019, 12:42:52 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

jamie

  • Hero Member
  • *****
  • Posts: 6134
Re: ComboBox and OnChange-event
« Reply #1 on: February 09, 2019, 02:41:32 pm »
if you are doing something in code and you expect it to trigger the Onchange event then
you must adjust your code to call the event directly yourself.

  Many events in such controls that get triggered via user input activity should not be
getting triggered via your code.

 Reason, for one its Delphi compatible and secondly there is a reason for this..

  I'll layout why..

  In many cases where a event gets called the code within the event could cause a retrigger
 of that same event and thus causing a loop!

 Also, you can not determine if user cause the event or your code did it.

 so if you can confirm that user activity does not trigger the event then you have a
reportable bug, otherwise, its working as it should be..

 If you need to call that even when you do something in code you can do so directly with
your code.
 
 Also, I think there is a flag setting in the options now to support the older way.

 I believe this was one of the few controls that were correct!
The only true wisdom is knowing you know nothing

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: ComboBox and OnChange-event
« Reply #2 on: February 10, 2019, 07:37:45 am »
The combobox is filled like this:
Code: Pascal  [Select][+][-]
  1.   cSQL :=
  2.     'SELECT SEI_ID, SEI_Periode, SEI_Letter ' +
  3.     'FROM tbl_Seizoenen ' +
  4.     'WHERE SEI_Tot <=  StrFTime ("%Y",' + SingleQuotedStr('Now') + ')+1 ' +
  5.     'UNION SELECT 0, "(All)", "Z" ' +
  6.     'ORDER BY SEI_Letter DESC;';
  7.   TQ_Seizoen.Active := False;
  8.   TQ_Seizoen.DataBase := Form_RefereeMain.Connect_RefereeDB;
  9.   TQ_Seizoen.SQL.Text := cSQL;
  10.   TQ_Seizoen.Active := True;
  11.   // setup TDBLookupCombobox
  12.   CB_Seizoen.ScrollListDataset := True;
  13.   CB_Seizoen.ListSource := DS_Seizoen;
  14.   CB_Seizoen.ListField := 'SEI_Periode';
  15.   CB_Seizoen.KeyField := 'SEI_ID';
  16.   CB_Seizoen.KeyValue := Form_RefereeMain.BepaalHuidigSeizoen; // Spring naar de actieve seizoen
So the user can change between different seasons.
When a user selects a different season the OnChange-event should kick in and then this code is triggered:
Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijden_Overzicht.CB_SeizoenChange(Sender: TObject);
  2. var cSQL: string;
  3. begin
  4.   if not TQ_Wedstrijden.Active then exit;
  5.   TQ_Wedstrijden.Active := False;
  6.   TQ_Wedstrijden.ParamByName('Sei_ID').Value := CB_Seizoen.KeyValue;
  7.   BepaalScheidsrechters;
  8.   if CB_Divisie.KeyValue=1 then
  9.     TQ_Wedstrijden.ParamByName('Divisie_ID').Value := 0
  10.   else
  11.     TQ_Wedstrijden.ParamByName('Divisie_ID').Value := CB_Divisie.KeyValue;
  12.   TQ_Wedstrijden.ParamByName('Scheids_ID').Value := CB_Scheidsrechters.KeyValue;
  13.  
  14.  
  15.   if TQ_Wedstrijden.ParamByName('Sei_ID').Value = null then TQ_Wedstrijden.ParamByName('Sei_ID').Value := 0;
  16.   if TQ_Wedstrijden.ParamByName('Divisie_ID').Value = null then TQ_Wedstrijden.ParamByName('Divisie_ID').Value := 0;
  17.   if TQ_Wedstrijden.ParamByName('Scheids_ID').Value = null then TQ_Wedstrijden.ParamByName('Scheids_ID').Value := 0;
  18.  
  19.  
  20.   TQ_Wedstrijden.Active := True;
  21.   TQ_Wedstrijden.Last;
  22.   TQ_Wedstrijden.First;
  23.   Grid_Wedstrijden.Refresh;
  24.   GroupBox_Wedstrijden.Caption :=
  25.     Format('Games (%d)', [TQ_Wedstrijden.RecordCount]);
  26.   if TQ_Wedstrijden.RecordCount = 0 then
  27.     Grid_Wedstrijden.Enabled := False
  28.   else begin
  29.     Grid_Wedstrijden.Enabled := True;
  30.     // Bepaal de wedstrijd die het dichtstbij de huidige datum ligt.
  31.     cSQL := 'SELECT Wed_ID, Wed_Datum, Wed_Tijd ' +
  32.             'FROM tbl_Wedstrijden ' +
  33.             'WHERE Date(Wed_Datum) >= Date() ' +
  34.             'ORDER BY Wed_Datum, Wed_Tijd';
  35.     with Form_RefereeMain do begin
  36.       TQ_Rapport.Active := False;
  37.       TQ_Rapport.DataBase := Connect_RefereeDB;
  38.       TQ_Rapport.SQL.Text := cSQL;
  39.       TQ_Rapport.Active := True;
  40.       TQ_Rapport.Last;
  41.       TQ_Rapport.First;
  42.       if TQ_Rapport.RecordCount > 0 then
  43.         SeekGridRecord (Grid_Wedstrijden, [0], TQ_Rapport.FieldByName('Wed_ID').AsString);
  44.     end;  // with
  45.   end;  // if
  46. end;     // CB_SeizoenChange


In Lazarus 1.8.4 when is changed to a different season the OnChange-event would be activated.
But in Lazarus 2.0.0 it isn't


So what am i doing wrong?
« Last Edit: February 10, 2019, 07:59:58 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

jamie

  • Hero Member
  • *****
  • Posts: 6134
Re: ComboBox and OnChange-event
« Reply #3 on: February 10, 2019, 03:16:18 pm »
I just ran a test on my windows machine and it works fine, only user input will trigger the event on the
combo box as it should.

 Maybe you should be using OnSelect instead ?

 Because the OnChange is basically something a little different like when you change the Edit text and when
you select the items in the list, this of course will change the EDIT text which triggers the OnChange event.

 So maybe you should be using the OnSelect in your code?

The only true wisdom is knowing you know nothing

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: ComboBox and OnChange-event
« Reply #4 on: February 11, 2019, 12:42:41 am »
The OnSelect-Event works like a charm
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

 

TinyPortal © 2005-2018