Recent

Author Topic: [SOLVED] TTabControl - How to get number of tabs?  (Read 5650 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
[SOLVED] TTabControl - How to get number of tabs?
« on: January 31, 2017, 04:55:53 am »
I'm working on an IDE, using a SynEdit and TTabControl for the tabs (I'm on OSX El Capitan).

I'm loading file content and creating tabs, but I can't figure out how to set the active tab of the TTabControl to the new tab.

My idea was to simply add the new tab and set the active tab to the count of the number of tabs.

This works once, but that's all.
Code: Pascal  [Select][+][-]
  1. TabControlFiles.TabIndex := TabControlFiles.RowCount;

This doesn't work at all
Code: Pascal  [Select][+][-]
  1. TabControlFiles.TabIndex := TabControlFiles.Tabs.Count;

I've looked on Google and searched the forum but no luck with this issue.

If anyone has an idea I'm open to it.
« Last Edit: January 31, 2017, 04:17:10 pm by Trenatos »

balazsszekely

  • Guest
Re: TTabControl - How to get number of tabs?
« Reply #1 on: January 31, 2017, 06:40:45 am »
Hi Trenatos,

Try this:
Code: Pascal  [Select][+][-]
  1.   TabControl1.Tabs.Add('New Tab');
  2.   TabControl1.TabIndex := TabControl1.Tabs.Count - 1;
It works for me under OSX.

derek.john.evans

  • Guest
Re: TTabControl - How to get number of tabs?
« Reply #2 on: January 31, 2017, 06:41:23 am »
Code: Pascal  [Select][+][-]
  1. TabControl1.TabIndex := TabControl1.Tabs.Add('New Tab');  
  2.  

But, I recommend using TPageControl over TTabControl. I believe TTabControl is there for historical reasons. ie: Delphi 1 compatible. The days before Microsoft COM controls.

Code: Pascal  [Select][+][-]
  1.   PageControl1.ActivePage := PageControl1.AddTabSheet;
  2.   PageControl1.ActivePage.Caption := 'New Tab';    
  3.  
« Last Edit: January 31, 2017, 06:43:14 am by Geepster »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: TTabControl - How to get number of tabs?
« Reply #3 on: January 31, 2017, 10:53:41 am »
Anyway for a tab control it is simply:
Code: Pascal  [Select][+][-]
  1. TabControl1.Tabs.Count;
Similar to page control....

Question: do you use code completion or not? Plz do not ask the obvious. Or try better. You are of course always welcome to ask questions but I am always allowed to be a little bit annoyed if the question should have been answered by yourself.
« Last Edit: January 31, 2017, 10:55:36 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: TTabControl - How to get number of tabs?
« Reply #4 on: January 31, 2017, 03:00:00 pm »
@GetMem Spot on mate, that -1 did the trick.

@Geepster With TPageControl I would have to use one SynEdit per page, this way I only need to use the one and update the content as I go.

@Thaddy I do use code completion, without it things would take about a hundred times longer.

I searched the web, I looked on the forum, what I did not think about is the fact that the Count starts at 1, but the Tabs are 0 based, which threw off the count.

I'm a CFML dev, our arrays are 1 based so this occasionally throws me.

Could it/should it have been self-answered, probably, but I did search and I did try and I failed, only then did I ask for help.

 

TinyPortal © 2005-2018