Okay so I'm using a TNotebook and TATTab to essentially do an MDI. Now for the most part that seems okay but I'm trying to close the tabs and the TPage that is essentially associated. I'm at the moment trying to close all for a desktop routine, it obviously wants to clear the opened files when loading. I'm getting errors all over the place here, access violations with these two procedures
procedure CloseAllTabs_ATTab(ATTab: TATTabs);
var
i: Integer;
begin
// remove from last to first to avoid index shifting
for i := ATTab.Tabs.Count - 1 downto 0 do
begin
// replace with the actual API your TATTab exposes:
// e.g. ATTab.Tabs.Delete(i); or ATTab.CloseTab(i); or ATTab.Pages[i].Free;
try
ATTab.Tabs.Items[i].Free;
except
end;
try
if assigned(ATTab.Tabs.Items[i]) then ATTab.Tabs.Delete(i);
except
//
end;
end;
application.ProcessMessages;
end;
procedure CloseAllNotebookPages(ANotebook: TNotebook);
var
i : Integer;
P : TWinControl;
begin
if ANotebook = nil then Exit;
// Prevent flicker and re-entrancy
ANotebook.DisableAlign;
try
// If Pages supports BeginUpdate/EndUpdate (TStrings), use them
if Assigned(ANotebook.Pages) then ANotebook.Pages.BeginUpdate;
try
// iterate backwards to avoid index shifting
for i := ANotebook.PageCount - 1 downto 0 do
begin
P := ANotebook.Page[i]; // TPage is a TWinControl descendant
p.hint := '';
// Free child controls on the page to avoid leaks and dangling events
// iterate while there are controls because Controls[] shifts when freed
while P.ControlCount > 0 do
begin
// Optionally remove event handlers here if needed
P.Controls[0].Parent := nil;
P.Controls[0].Free;
end;
try
if assigned(p) then ANotebook.Pages.Delete(i);
except
end;
try
FreeAndNil(p);
except
//
end;
end;
finally
try
if Assigned(ANotebook.Pages) then ANotebook.Pages.EndUpdate;
except
//
end;
end;
finally
ANotebook.EnableAlign;
end;
end;
I'm using this :-
procedure TfrmMain.CloseAllTabs;
begin
if FLoading then exit;
if tabMDI.tabCount-1=-1 then exit; // Nothing to close so exit clean
try
CloseAllNotebookPages(nbMDI);
except
//
end;
application.ProcessMessages;
sleep(15);
try
CloseAllTabs_ATTab(tabMDI);
except
//
end;
end;
to actually do the closing. Right now it does close the windows (with an access violation) but it doesn't appear to actually be freeing both the tabs and the TPage. I've messed around as best I can but it still doesn't work when then obviously I want to open the new desktop of filenames. I *think* because it thinks the tabs and pages are still there somehow.
If anyone can help me with this migraine inducing issue I would be very happy

. I'm using Lazarus 4.2 and I'm using the ATFlat controls package from the online package manager that to my knowledge is up-to-date.
Please, this will really help me, thanks
CJ