Another bug in Latest update - ComboChange

This is the second bug I've found in the latest release of TMS.  We are now going to revert back to the previous version until we are confident all issues are resolved.

 
Problem: The ComboChange event handler no longer gives the new selections in the AItemIndex and ASelection parameters, if the TAdvStringGrid object has the ControlLook.DropDownAlwaysVisible property set to true.  It will incorrectly give the values before the change is made.
 
The following code demonstrates the problem:
1. Drop a TAdvStringGrid on a form.
 
2. Add CanEditCell handler:
procedure TForm34.AdvStringGrid1CanEditCell(Sender: TObject; ARow,
  ACol: Integer; var CanEdit: Boolean);
begin
   if( aCol = 1 ) and (aRow > 0) then
      CanEdit := true;
end;
 
3. Add OnComboChange handler:
procedure TForm34.AdvStringGrid1ComboChange(Sender: TObject; ACol, ARow,
  AItemIndex: Integer; ASelection: string);
begin
   showMessage( 'Looks like you selected: ' + ASelection );
end;
 
4. Add GetEditorType handler:
procedure TForm34.AdvStringGrid1GetEditorType(Sender: TObject; ACol,
  ARow: Integer; var AEditor: TEditorType);
begin
   if( aCol = 1 ) and (aRow > 0) then
   begin
      aEditor := edComboList;
      AdvStringGrid1.Combobox.Items.Clear;
      AdvStringGrid1.Combobox.Items.Text := 'One'#13#10'Two'#13#10'Three';
      AdvStringGrid1.Combobox.ItemIndex := AdvStringGrid1.Combobox.Items.IndexOf( AdvStringGrid1.Cells[ ACol, ARow ] );
   end;
end;
 
5. Add HasComboBox handler:
procedure TForm34.AdvStringGrid1HasComboBox(Sender: TObject; ACol,
  ARow: Integer; var HasComboBox: Boolean);
begin
   if( aCol = 1 ) and (aRow > 0) then
      HasComboBox := true;
end;
 
6. Add FormCreate Handler:
procedure TForm34.FormCreate(Sender: TObject);
begin
   // Comment out the line below, and the ComboChange event acts as expected
   AdvStringGrid1.ControlLook.DropDownAlwaysVisible := true;
   AdvStringGrid1.Cells[1, 2] := 'Two';
end;
 
 

Data for the combobox should be set from OnGetEditorProp, not OnGetEditorType.
Correct code is:


procedure TForm4.AdvStringGrid1CanEditCell(Sender: TObject; ARow, ACol: Integer;
  var CanEdit: Boolean);
begin
  if( aCol = 1 ) and (aRow > 0) then
    CanEdit := true;
end;

procedure TForm4.AdvStringGrid1ComboChange(Sender: TObject; ACol, ARow,
  AItemIndex: Integer; ASelection: string);
begin
  listbox1.Items.Add(ASelection);
end;

procedure TForm4.AdvStringGrid1GetEditorProp(Sender: TObject; ACol,
  ARow: Integer; AEditLink: TEditLink);
begin
  if( aCol = 1 ) and (aRow > 0) then
  begin
    AdvStringGrid1.Combobox.Items.Clear;
    AdvStringGrid1.Combobox.Items.Text := 'One'#13#10'Two'#13#10'Three';
    AdvStringGrid1.Combobox.ItemIndex := AdvStringGrid1.Combobox.Items.IndexOf( AdvStringGrid1.Cells[ ACol, ARow ] );
  end;
end;

procedure TForm4.AdvStringGrid1GetEditorType(Sender: TObject; ACol,
  ARow: Integer; var AEditor: TEditorType);
begin
  if( aCol = 1 ) and (aRow > 0) then
  begin
    aEditor := edComboList;
  end;
end;

procedure TForm4.AdvStringGrid1HasComboBox(Sender: TObject; ACol, ARow: Integer;
  var HasComboBox: Boolean);
begin
  if( aCol = 1 ) and (aRow > 0) then
    HasComboBox := true;
end;

procedure TForm4.FormCreate(Sender: TObject);
begin
  AdvStringGrid1.ControlLook.DropDownAlwaysVisible := true;
  AdvStringGrid1.Cells[1, 2] := 'Two';
end;

Thanks, that seems to correct the issue. 

But, I would strongly advise you to update your examples, because pages like this:
http://www.tmssoftware.com/site/asg5.asp
 
currently use the OnGetEditorType event to populate the combobox, not the OnGetEditorProp.  The fact that the code did work before this latest update didn't help in trying to identify the problem.
 

We have updated this specific article 5 now.