Bug in TmsAdvStringGrid? (WMLButtonUp -> IsEditableInt -> GetCellFixed)

Hi,
i have an TAdvStringGrid (ver. 8.6.14.2) with a few hidden Columns and few Colums with CellButtons.
OnButtonClick does'nt work for Cells that are behind any invisible col, and i think there is a Bug in

procedure TAdvStringGrid.WMLButtonUp(var Msg: TWMLButtonUp);
[...]
  if (FPushedCellButton.x <> -1) {and (x > -1) and (y > -1)} then
  begin
    Canedit := (goEditing in Options);

    bc := Point(x,y);
    rx := RemapCol(x);

    if (x > -1) and (y > -1) then
    begin
      if not ControlLook.NoDisabledButtonLook then
        CanEdit := IsEditableInt(rx,y);
      bc := BaseCell(x,y);
    end;

For my understanding the call of IsEditableInt needs an DisplayColumn Index - NOT an RealColumn Index (RemapCol(x) in above snippet) because there is a call to GetCellFixed with this Index in IsEditableInt().

function TAdvStringGrid.IsEditableInt(ACol,ARow: Integer): Boolean;
var
IsFixed,IsEdit: Boolean;
BC: TPoint;

begin
if IsMergedCell(ACol, ARow) and not IsBaseCell(ACol, ARow) then
BC := BaseCell(ACol,ARow)
else
BC := Point(ACol,ARow);

IsFixed := False;
IsEdit := True;

GetCellReadOnly(BC.X,BC.Y,IsEdit);
GetCellFixed(BC.X,BC.Y,IsFixed);
Result := IsEdit and not IsFixed;
end;

please have a look into this.

With the information provided, I cannot reproduce this with TAdvStringGrid 8.7.0.0 and test code:

procedure TForm1.AdvStringGrid1ButtonClick(Sender: TObject; ACol,
  ARow: Integer);
begin
  ShowMessage('button click:'+ACol.ToString);
end;

procedure TForm1.AdvStringGrid1CanEditCell(Sender: TObject; ARow, ACol: Integer;
  var CanEdit: Boolean);
begin
  CanEdit := ACol <> 3;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 5 do
  begin
    advstringgrid1.Cells[i,0] := i.ToString;
    advstringgrid1.AddButton(i,1,30,20,chr(64+i),haLeft, vaTop);
  end;

  advstringgrid1.HideColumn(2);
  advstringgrid1.Options := advstringgrid1.Options + [goEditing];
end;

try this:

> procedure TGridTestForm.AdvStringGrid1ButtonClick(Sender: TObject; ACol, ARow: Integer);
> begin
>   ShowMessage('button click:'+ACol.ToString);
> end;
> 
> procedure TGridTestForm.AdvStringGrid1IsFixedCell(Sender: TObject; ARow, ACol: Integer; var IsFixed: Boolean);
> begin
>   isFixed := aCol = 3;  // <-- Display Index 3, real Index 4 
> end;
> 
> procedure TGridTestForm.FormCreate(Sender: TObject);
> var i: integer;
> begin
>   for i := 1 to 5 do
>     advstringgrid1.Cells[i,0] := i.ToString;
>   advstringgrid1.AddButton(3,1,30,20,chr(64+i),haLeft, vaTop);   // Button at column 3 <--
>   advstringgrid1.HideColumn(2);
>   advstringgrid1.Options := advstringgrid1.Options + [goEditing];
> end;

this will show the Button in column "3" and a Fixed Column "4"

But the Button will not work because of the call to IsFixedCell with ACol=3 instead of ACol=2 (IsFixedCell uses the Display Index) ...

Ok, the problem was related to fixed cell use for defining non editable cells.
We could now reproduce this and we applied a fix that will be included in the next update.

thank you.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.