Problem setting focus on MS Dialog tab

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Problem setting focus on MS Dialog tab

Post by Jerry Thomas » Wed Sep 14, 2011 10:58 pm

My app allows switching tabs and then hides unused tabs.
But when you switch, that tab should have the focus.
Instead the focus switches to the permanent tab.

To repro:
Run this
Select Button 1, 2 or 3
Keep selecting different buttons
Note focus does not go to the tab 'selected' even with SetDialogObjectFocus

Any suggestions?

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 1992
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 299
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 29
    Top = 78
    Width = 372
    Height = 187
    ActivePage = Page3
    TabOrder = 0
    object AlwaysShows: TTabSheet
      Caption = 'Always Shows'
      ExplicitTop = 56
    end
    object Page1: TTabSheet
      Caption = 'Page1'
    end
    object Page2: TTabSheet
      Caption = 'Page2'
    end
    object Page3: TTabSheet
      Caption = 'Page3'
    end
  end
  object MSButton1: tMSButton
    Left = 28
    Top = 20
    Width = 75
    Height = 25
    Caption = '1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 20
    Width = 75
    Height = 25
    Caption = '2'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 237
    Top = 20
    Width = 75
    Height = 25
    Caption = '3'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

ADH>Dialog1,MSButton1,OnClick,ButtonClick1
ADH>Dialog1,MSButton2,OnClick,ButtonClick2
ADH>Dialog1,MSButton3,OnClick,ButtonClick3

Show>Dialog1,r

SRT>ButtonClick1
  SDP>Dialog1,Page1,TabVisible,True
  SDP>Dialog1,Page2,TabVisible,False
  SDP>Dialog1,Page3,TabVisible,False
  SetDialogObjectFocus>Dialog1,Page1
END>ButtonClick1

SRT>ButtonClick2
  SDP>Dialog1,Page1,TabVisible,False
  SDP>Dialog1,Page2,TabVisible,True
  SDP>Dialog1,Page3,TabVisible,False
  SetDialogObjectFocus>Dialog1,Page2
END>ButtonClick2

SRT>ButtonClick3
  SDP>Dialog1,Page1,TabVisible,False
  SDP>Dialog1,Page2,TabVisible,False
  SDP>Dialog1,Page3,TabVisible,True
  SetDialogObjectFocus>Dialog1,Page3
END>ButtonClick3
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 15, 2011 3:25 am

Try this

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 1992
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 299
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 29
    Top = 78
    Width = 372
    Height = 187
    ActivePage = Page3
    TabOrder = 0
    object AlwaysShows: TTabSheet
      Caption = 'Always Shows'
      ExplicitTop = 56
    end
    object Page1: TTabSheet
      Caption = 'Page1'
    end
    object Page2: TTabSheet
      Caption = 'Page2'
    end
    object Page3: TTabSheet
      Caption = 'Page3'
    end
  end
  object MSButton1: tMSButton
    Left = 28
    Top = 20
    Width = 75
    Height = 25
    Caption = '1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 20
    Width = 75
    Height = 25
    Caption = '2'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 237
    Top = 20
    Width = 75
    Height = 25
    Caption = '3'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

ADH>Dialog1,MSButton1,OnClick,ButtonClick1
ADH>Dialog1,MSButton2,OnClick,ButtonClick2
ADH>Dialog1,MSButton3,OnClick,ButtonClick3

Show>Dialog1,r

SRT>ButtonClick1
  SDP>Dialog1,AlwaysShows,TabVisible,False
  SDP>Dialog1,Page1,TabVisible,True
  SDP>Dialog1,Page2,TabVisible,False
  SDP>Dialog1,Page3,TabVisible,False
  SDP>Dialog1,AlwaysShows,TabVisible,True
END>ButtonClick1

SRT>ButtonClick2
  SDP>Dialog1,AlwaysShows,TabVisible,False
  SDP>Dialog1,Page2,TabVisible,True
  SDP>Dialog1,Page1,TabVisible,False
  SDP>Dialog1,Page3,TabVisible,False
  SDP>Dialog1,AlwaysShows,TabVisible,True
END>ButtonClick2

SRT>ButtonClick3
  SDP>Dialog1,AlwaysShows,TabVisible,False
  SDP>Dialog1,Page3,TabVisible,True
  SDP>Dialog1,Page1,TabVisible,False
  SDP>Dialog1,Page2,TabVisible,False
  SDP>Dialog1,AlwaysShows,TabVisible,True
END>ButtonClick3

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Sep 15, 2011 6:04 pm

Thanks that works!

But it doesn't make sense.
Why does hiding and then showing 'Always Shows' make this work?
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 15, 2011 10:09 pm

I can't really explain why.

I do know that the order of the lines of code can sometimes make a difference in whether the script performs correctly. Since like you I could not get the TTabSheet objects to focus, I started playing around with the order of the SetDialogProperty> lines in your buttonclick subroutines. I noticed that when the object that was assigned the value "True", is the first in line, if one only selects buttons, the "PageX" tabs always remain focused. However if you pick the "AlwaysShows" tab, focus would not return to the "PageX" tabs.

Then I discovered if you make the object that was assigned the value "True" the last in line, the "PageX" tabs will never get focus when you pick the buttons. So it made sense to put the "True" "PageX" tabs at the top of the list and put a SDP>Dialog1,AlwaysShows,TabVisible,True line at the end of the list so the "AlwaysShows" tab would always lose focus. But, for whatever reason, that still didn't work... but I knew it was close... so I put the SDP>Dialog1,AlwaysShows,TabVisible,False in the subs and that made it work correctly.

Now you know everything I know which is very little. There may be a better way, I tend to stop looking when I find concise working code.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Sep 16, 2011 2:07 pm

I tend to stop looking when I find concise working code.
I agree.



Thanks again for the assist!
Thanks,
Jerry

[email protected]

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts