Thank you for your code lucamar, it's very educational to see multiple ways of doing things.
I'm still struggling with a bug that I've been trying to wrap my head around for hours now. On my form, the PageControl is controlled by a ListBox with the following code:
procedure TForm1.ListBox1SelectionChange(Sender: TObject; User: boolean);
var
NewTab: TTabSheet;
NewStringGrid: TStringGrid;
begin
NewTab := PageControl1.ActivePage;
NewStringGrid := TStringGrid(NewTab.Tag);
PageControl1.TabIndex := ListBox1.ItemIndex;
// problem code below
If NewStringGrid.RowCount = 1 then
begin
Button1.Enabled := False;
end
else
Button1.Enabled := True;
end;
The problem with this code is, when I switch tab (using ListBox1SelectionChange), if the StringGrid within that tab has
RowCount = 1, the Button1 does not disable, until I change the ListBox1Selection/tab again. It's as though this code is referencing the StringGrid prior to the change in selection/tab, rather than the StringGrid in the newly selected page. Does anyone know a fix to this issue?
Thank you.