Set Active Page of Page Control

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Set Active Page of Page Control

Post by Dominic_Fichera » Thu May 19, 2016 2:12 am

Hey all,

I'm trying to add a "password protected" tab to my page control. Essentially, I want the tab to prompt users to enter a password, and if it's wrong, bounce them back to another tab. So far, I've got a sub routine that's triggered when the tab is shown (onShow), and it prompts users to enter the password. If it's correct, it stays put, if it's incorrect, it bounces them to another tab. This is perfect for what I want, and seems to do the trick when stepping through using the debugger, but when the SRT ends, the page just bounces back to the "password protected" tab. Anyone have any ideas why this might be happening?

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 2167
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 192
  ClientWidth = 287
  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 = 0
    Top = 0
    Width = 289
    Height = 193
    ActivePage = Page1
    TabOrder = 0
    object Page1: TTabSheet
      Caption = 'Page1'
    end
    object Page2: TTabSheet
      Caption = 'Page2'
    end
    object TTabSheet
      Caption = 'Page3'
      ExplicitLeft = 0
      ExplicitTop = 0
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TTabSheet
      Caption = 'Page4'
      ExplicitLeft = 0
      ExplicitTop = 0
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,Page2,onShow,doAskPassword
Show>Dialog1
Label>IdleMainMenuLoop
    Wait>.001
GoTo>IdleMainMenuLoop

SRT>doAskPassword
    Input>varPassword,Please enter the password:
    If>varPassword=123
        //Run code
    Else
        SetDialogProperty>Dialog1,Pagecontrol1,TabIndex,0
    Endif
END>doAskPassword

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Set Active Page of Page Control

Post by hagchr » Thu May 19, 2016 8:43 am

Another way to protect the tab could be to use the visibility property. Simple example below.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 211
  ClientWidth = 476
  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 = 0
    Top = 0
    Width = 289
    Height = 193
    ActivePage = Page2
    TabOrder = 0
    object Page1: TTabSheet
      Caption = 'Page1'
    end
    object Page2: TTabSheet
      Caption = 'Page2'
      object MSButton1: tMSButton
        Left = 166
        Top = 110
        Width = 75
        Height = 25
        Caption = 'Lock'
        TabOrder = 0
        DoBrowse = False
        BrowseStyle = fbOpen
      end
    end
    object TTabSheet
      Caption = 'Page3'
    end
    object TTabSheet
      Caption = 'Page4'
    end
  end
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,Page2,Visible,FALSE
AddDialogHandler>Dialog1,Page2,onShow,doAskPassword
AddDialogHandler>Dialog1,msButton1,onClick,doLock

Show>Dialog1
Let>flag=FALSE

Label>IdleMainMenuLoop
    Wait>.001
GoTo>IdleMainMenuLoop

SRT>doAskPassword
    If>flag=FALSE
        SetDialogProperty>Dialog1,Page2,Visible,FALSE
        Input>varPassword,Please enter the password:
        If>varPassword=123
            MDL>Password Correct!
            Let>flag=TRUE
            SetDialogProperty>Dialog1,Page2,Visible,TRUE
        Else
            MDL>Password Incorrect!
        Endif
    Endif
END>doAskPassword

SRT>doLock
  SetDialogProperty>Dialog1,Page2,Visible,FALSE
  Let>flag=FALSE
END>doLock

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Set Active Page of Page Control

Post by hagchr » Thu May 19, 2016 9:29 am

I looked at your original question, seems as it somehow resets to Page2 after the SRT has completed. If you still want to switch to another page you could use a flag to control it, eg:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 192
  ClientWidth = 287
  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 = 0
    Top = 0
    Width = 289
    Height = 193
    TabOrder = 0
    object Page1: TTabSheet
      Caption = 'Page1'
    end
    object Page2: TTabSheet
      Caption = 'Page2'
    end
    object TTabSheet
      Caption = 'Page3'
    end
    object TTabSheet
      Caption = 'Page4'
    end
  end
end
EndDialog>Dialog1
Let>flag=FALSE

AddDialogHandler>Dialog1,Page2,onShow,doAskPassword
Show>Dialog1

Label>IdleMainMenuLoop
    Wait>.001
    Gosub>chkflag
GoTo>IdleMainMenuLoop

SRT>doAskPassword
    Input>varPassword,Please enter the password:
    If>varPassword=123
        Let>flag=FALSE
        //Run code
    Else
        SetDialogProperty>Dialog1,PageControl1,TabIndex,3
        Let>flag=TRUE
    Endif
END>doAskPassword

SRT>chkflag
    If>flag=TRUE
        SetDialogProperty>Dialog1,PageControl1,TabIndex,0
        Let>flag=FALSE
    Endif
END>chkflag

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Set Active Page of Page Control

Post by Dominic_Fichera » Mon May 23, 2016 12:11 am

Hey Hagchr,

sorry for the delayed response back to you.

I've given both of these solutions a go, combining a couple of ideas, and it's working really well! Thanks so much!

Dominic Fichera

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