It's legal for ActiveGrid() to return nil, as there are tabs without a data- or querygrid. Fix relevant functions so they don't barf with a "List index out of bounds" violation. Fixes issue #1320

This commit is contained in:
Ansgar Becker
2009-08-25 21:37:34 +00:00
parent 45eba2139c
commit 6df4b7a706

View File

@ -9368,8 +9368,14 @@ end;
function TMainForm.ActiveQueryTab: TQueryTab;
var
idx: Integer;
begin
Result := QueryTabs[PageControlMain.ActivePageIndex-tabQuery.PageIndex] as TQueryTab;
idx := PageControlMain.ActivePageIndex-tabQuery.PageIndex;
if (idx >= 0) and (idx < QueryTabs.Count) then
Result := QueryTabs[idx] as TQueryTab
else
Result := nil;
end;
@ -9396,8 +9402,10 @@ end;
function TMainForm.ActiveGrid: TVirtualStringTree;
begin
Result := nil;
if PageControlMain.ActivePage = tabData then Result := DataGrid
else Result := ActiveQueryTab.Grid;
else if ActiveQueryTab <> nil then
Result := ActiveQueryTab.Grid;
end;