View Issue Details

IDProjectCategoryView StatusLast Update
0027467LazarusLCLpublic2018-07-17 00:05
ReporterSimon AmeisAssigned ToMichl 
Status resolvedResolutionfixed 
PlatformOSWindowsOS Version8.1 64bit
Product Version1.3 (SVN)Product Build47519 
Target Version1.6.4Fixed in Version1.7 (SVN) 
Summary0027467: TTabControl.IndexOfTabAt() always returns -1
DescriptionThe method TTabControl.IndexOfTabAt() always returns -1 regardless of the point clicked.
Steps To ReproducePlace a TTabControl on a form, add a PopupMenu with one MenuItem. Also assign an event handler to OnContextPopup of the tab control.
Inside the event handler place the call to IndexOfTabAt() like
procedure TForm1.TabControl1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
  IdxTab: Integer;
  IdxTab := TabControl1.IndexOfTabAt(MousePos.X, MousePos.Y);
Additional InformationMay be related to 0024022
TagsNo tags attached.
Fixed in Revisionr53978
Attached Files


related to 0024022 resolvedMichl TTabControl (Drag and Drop) don't work 
related to 0030343 closedMichl TPageControl.IndexofTabAt returning wrong values when some tabs are hidden. 


Bart Broersma

2015-02-14 16:49

developer   ~0081069

Delphi 7 does the same: it is always -1.

Bart Broersma

2015-02-28 18:18

developer   ~0081512

Last edited: 2015-02-28 18:35

View 5 revisions

First an observation: clicking or moving the mouse over a Tab of a TTabControl does not firen the TabControls OnMouseDown/onMouseMove, only if the mouse is inside the "clientarea" (?) these events are triggered.
In Delphi 7 it is exactly the other way around.

However I was able to obtain the correct index using this code (in TabControl's MouseDown):

  Pt := (Point(X,Y));
    Pt.Y := -5;
    Idx := TabControl1.IndexOfTabAt(Pt.X,Pt.Y)

I noticed that on a TPageControl the Y value when you are over the tab is negative, so I experimented with that a bit for TTabControl.

This only works when TabPosition = tTop, if it is tpBottom it works with positive Y.
With tpLeft set X to -5, with tRight set X to +5.

Martin Friebe

2015-02-28 22:04

manager   ~0081515

Well first a decision is needed:
IndexOfTabAt is the same as TabIndexAtClientPos

Should it be? Or should it take global coordinates?

The following works on windows:
p := PageControl1.ScreenToClient(Mouse.CursorPos);

IMHO the negative coordinates are correct. IIRC if you click in the empty space to the right of the last tab (where further tabs could be), the click goes to the control below. afaik This is consistent with the hittest message send by windows. (You will also see that if you place a label there, it remains visible)

Alexey Tor.

2017-01-16 00:26

reporter   ~0097515

Related to fixed 0030343


2017-01-21 23:19

developer   ~0097624

Fixed in trunk. Please test and close if ok.

Alexey Tor.

2017-01-22 21:12

reporter   ~0097635

Last edited: 2017-01-22 21:12

View 2 revisions

Thank u for this patch.Can I make new version of my patch for TabWidth/height for Win32?

Issue History

Date Modified Username Field Change
2015-02-14 13:51 Simon Ameis New Issue
2015-02-14 14:23 Juha Manninen Relationship added related to 0024022
2015-02-14 16:49 Bart Broersma Note Added: 0081069
2015-02-28 18:18 Bart Broersma Note Added: 0081512
2015-02-28 18:26 Bart Broersma Note Edited: 0081512 View Revisions
2015-02-28 18:33 Bart Broersma Note Edited: 0081512 View Revisions
2015-02-28 18:34 Bart Broersma Note Edited: 0081512 View Revisions
2015-02-28 18:35 Bart Broersma Note Edited: 0081512 View Revisions
2015-02-28 22:04 Martin Friebe Note Added: 0081515
2016-07-05 13:53 Juha Manninen Relationship added related to 0030343
2017-01-16 00:26 Alexey Tor. Note Added: 0097515
2017-01-21 23:19 Michl Fixed in Revision => r53978
2017-01-21 23:19 Michl LazTarget => 1.6.4
2017-01-21 23:19 Michl Note Added: 0097624
2017-01-21 23:19 Michl Status new => resolved
2017-01-21 23:19 Michl Fixed in Version => 1.7 (SVN)
2017-01-21 23:19 Michl Resolution open => fixed
2017-01-21 23:19 Michl Assigned To => Michl
2017-01-21 23:19 Michl Target Version => 1.6.4
2017-01-22 21:12 Alexey Tor. Note Added: 0097635
2017-01-22 21:12 Alexey Tor. Note Edited: 0097635 View Revisions