Hello,
I'm nearing a solution with regards to numbering my tabs. This is how the tabs should look like:
Web Browser - Untitled | HTML Viewer - Untitled | Web Browser - Untitled 1 | HTML Viewer - Untitled 1| Web Browser - Untitled 2 | HTML Viewer - Untitled 2 |
Unfortunately, the untitled number goes up like this: 1, 3, 5, 7
It's clear why, when you look at this code, however, I'm struggling mathematically to find a solution for the pairs of tabs to go up like: 1, 2, 3, 4.
This probably isn't as complex as it sounds, however I'm not very good at math (as I'm still learning it is school - I'm 13).
Does anybody know of a solution?
If you want to test it in a project, just create a form with a Button and a PageControl and copy/paste the following code:
procedure TForm1.FormCreate(Sender: TObject);
begin
SheetBrowser := TTabSheet.Create (PageControl1);
SheetBrowser.PageControl := PageControl1;
SheetBrowser.Caption := 'Web Browser - Untitled';
SheetHTML := TTabSheet.Create (PageControl1);
SheetHTML.PageControl := PageControl1;
SheetHTML.Caption := 'HTML Viewer - Untitled';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Ind := -1;
Comp := FindComponent('SheetHTML');
if Assigned(Comp) then
if Comp is TTabSheet then
Index := TTabSheet(Comp).PageIndex;
SheetBrowser := TTabSheet.Create(PageControl1);
SheetBrowser.PageControl := PageControl1;
SheetBrowser.Caption := 'Web Browser - Untitled '+IntToStr(PageControl1.PageCount -2); // This is where the math problem is - the -2 stops the first page being named "Web Browser - Untitled 3 (due to the existence of the first two tabs)
SheetHTML := TTabSheet.Create(PageControl1);
SheetHTML.PageControl := PageControl1;
SheetHTML.Caption := 'HTML Viewer - Unitled '+IntToStr(PageControl1.PageCount -3); // Subtract 3 to account for the previous tab being added - this makes it the same number - Untitled 1, Untitled 1
end;
The variable declarations:
var
Form1: TForm1;
SheetBrowser: TTabSheet;
SheetHTML: TTabSheet;
Ind: Integer;
Comp: TComponent;
Thanks for the help!