A small - though significant - issue has now reveiled itself after some further testing
These Grids would normally be hidden ('Visible' := false) and only shown when the user requests it by clicking on a TButton and hidden again with a second 'click' - the Caption is changed at each event to reflect the current state.
This works well, the grid gets populated correctly with data derived from pre-read arrays and column widths & titles are modified/hidden/shown. At the initial point of display (Grid.Show) no cell has been selected so the aRow & aCol properties are essentially 'undefined' - - - I do initialize them to Zero within the procedure 'OnClick' but all my attempts to inhibit the SelectCell from wanting to 'fire' have come to naught.
ie. The data for a Thread (screw - not program!) exists but when the Grid is displayed a new set of figures are calculated and displayed -- before a Grid Cell has been 'clicked'.
I've even tried delaying the 'Grid.Enabled' until after a genuine 'selection' has been made. (Line 16 in the 'Sellect' code fragment and Line 50 in the OnClick fragment)
I'm never sure how much 'code' to provide so that it is useful but not simply confusing but I do know that you cannot advise 'blind' .
This is the 'Select' proc.
procedure TForm1.StandardGridSelectCell(Sender: TObject;
aCol, aRow: Integer;
var CanSelect: Boolean);
Var
R,C : byte;
T,P : single;
procedure ShowStandardName(F,R : byte);
begin
[...]
end;
begin
R := aRow-1;
C := aCol;
Err := false;
StandardGrid.Enabled:=true; // moved from OnClick
If StandardGrid.Cells[C,aRow] = '-' then
begin
beep(1200,700);
end
else
begin
If (C > 1) then
begin
Thread.Diam:=StrToFloat(UNIV_Std[R].D) + 0.000001;
Case Thread.Form of
0,7,8 : begin
case C of
2 : P:=UNIV_Std[R].C;
3 : P:=UNIV_Std[R].F;
4 : P:=UNIV_Std[R].E;
end;
if P=0 then
begin
P := 1;
Beep(1200,500);
Err := true;
end;
Thread.Pitch:= Trunc(P * 100 + 0.00001) / 100;
Thread.TPI := I2M / Thread.Pitch;
TPI_Param.Caption :=Trim(Dot(FloatToStr(Thread.TPI/Mil)),6);
Pitch_Param.Caption :=Trim(Dot(FloatToStr(Thread.Pitch)),6);
end;
1,2,
4,6 : begin
[...]
end;
end;
Calc_and_Show;
if not Err then
ShowStandardName(Thread.Form,C);
end;
end;
end;
and this is the 'OnClick' code
begin
procedure TForm1.ShowStandardClick(Sender: TObject);
Var
L : byte;
procedure PopulateMetr;
begin
[...]
end;
procedure PopulateWhit;
begin
[...]
end;
[...]
procedure SetWidths(a,b,c,d,e : byte);
begin
StandardGrid.ColWidths[0]:= a;
[...]
end;
if ShowStandard.Caption[1] = 'S' then
begin
ShowStandard.Caption := 'Close Standard';
StandardGrid.Row := 0;
StandardGrid.Col := 0;
Case Thread.Form of
0 : begin // Metric
L := high(Metr_Std)+1;
StandardGrid.RowCount := L+1;
SetWidths(0,40,60,50,0);
StandardGrid.Columns[1].Alignment:=taRightJustify;
StandardGrid.Columns[1].Title.Caption :='Dia. ';
StandardGrid.Columns[2].Title.Caption :='Coarse';
StandardGrid.Columns[3].Title.Caption :='Fine';
PopulateMetr;
StandardGrid.Height := 5 + (L+1) * StandardGrid.DefaultRowHeight;
end;
1 : begin // Whit
[...]
end;
2 : begin // Unified
[...]
end;
[...]
end;
Close_StdGrid.Left:=1010;
Close_StdGrid.Show;
// StandardGrid.Enabled:=true;
StandardGrid.Show;
end
else
begin
Std_Entry := 0;
ShowStandard.Caption := 'Show Standard';
Form1.Width:=1020;
StandardGrid.Enabled:=false;
StandardGrid.Hide;
Close_StdGrid.Hide;
Constraints.MaxWidth := 1020;
Set_Form_Left;
end;
end;
I do hope that I've struck a suitable balance by editing out repetetive (though different) code.