TTabSet - Wrong tab positions in Delphi XE8

Viewed 235

In a Delphi project I use the somewhat antique (but nevertheless still useful) TTabSet VCL component with a total of 26 tabs (labeled 'A' to 'Z'). Everything worked fine when compiled with Delphi 7. With Delphi XE8, however, the TTabSet method ItemAtPos returns slightly wrong values. This published method which is also used internally for determining the index of the clicked tab may finally cause the wrong tab to be selected. This bug becomes paticularly prominent when clicking a tab having a rather high tab index. In my project clicking the 'X' or 'Y' tab e.g. will cause the 'Z' tab to be selected. This behavior has been observed with both the Classic Look as well with the Aero Look of Windows 7.

As a preliminary workaround I have sucessfully patched and recompiled the unit Vcl.Tabs.pas in the following way: In the function TTabSet.ItemAtPos(...) I have slightly modified the formulas for calculating the local variables MinLeft and MaxRight as shown in the following code snippet (lines 958 to 975):

    for I := 0 to FTabPositions.Count - 1 do
    begin
      TabPos := TTabPos(FTabPositions[I]);
//***************** original Delphi XE8 ********************
{
      MinLeft := TabPos.StartPos - Extra;
      MaxRight := TabPos.StartPos + TabPos.Size + Extra;
}
//******************* Michael's patch **********************
      MinLeft  := TabPos.StartPos               - Extra + I;
      MaxRight := TabPos.StartPos + TabPos.Size + Extra + I;
//**********************************************************
      if (Pos.X >= MinLeft) and (Pos.X <= MaxRight) then
      begin
        Result := FirstIndex + I;
        Break;
      end;
    end;

With this patch, now everything works fine also with Delphi XE8.

Question: Is this a viable way to deal with this obvious bug or does anybody else have a better idea to solve this problem?

0 Answers
Related