Solved

Tab order

Posted on 2004-10-14
9
234 Views
Last Modified: 2010-04-05
By pressing the tab key I don'want to cycle through all the controls on my form. Say I've got to panels. If a control on the the right panel is focused I want to cycle through controls on the right panel, same for the left panel. Can anyone help? Thank you!
0
Comment
Question by:__alex
  • 3
  • 3
  • 3
9 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 12306944
You mean like this?

object Form2: TForm2
  Left = 206
  Top = 284
  Width = 696
  Height = 480
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 48
    Top = 64
    Width = 185
    Height = 229
    Caption = 'Panel1'
    TabOrder = 0
    object Edit1: TEdit
      Left = 40
      Top = 24
      Width = 121
      Height = 21
      TabOrder = 0
      Text = 'Edit1'
    end
    object Edit2: TEdit
      Left = 40
      Top = 60
      Width = 121
      Height = 21
      TabOrder = 1
      Text = 'Edit2'
    end
    object Button1: TButton
      Left = 100
      Top = 124
      Width = 75
      Height = 25
      Caption = 'Focus other'
      TabOrder = 2
      OnEnter = Button1Enter
    end
  end
  object Panel2: TPanel
    Left = 296
    Top = 68
    Width = 185
    Height = 233
    Caption = 'Panel2'
    TabOrder = 1
    object Edit3: TEdit
      Left = 12
      Top = 24
      Width = 121
      Height = 21
      TabOrder = 0
      Text = 'Edit3'
    end
    object Edit4: TEdit
      Left = 12
      Top = 64
      Width = 121
      Height = 21
      TabOrder = 1
      Text = 'Edit4'
    end
    object Button2: TButton
      Left = 8
      Top = 116
      Width = 75
      Height = 25
      Caption = 'Button2'
      TabOrder = 2
      OnEnter = Button2Enter
    end
  end
end
0
 
LVL 11

Accepted Solution

by:
calinutz earned 200 total points
ID: 12306950
And the code here...

procedure TForm2.Button1Enter(Sender: TObject);
begin
Edit3.SetFocus;
end;

procedure TForm2.Button2Enter(Sender: TObject);
begin
Edit1.SetFocus;
end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 12306973
It is just about setting the tab order for the controls on the 2 panels , and setting the OnEnter Event of the Control that you want to use to jump on the other panel.
My code jumps to the other panel when the button control gets focus. You can use any other control that has an OnEnter event.
Cheers  
0
 
LVL 2

Author Comment

by:__alex
ID: 12307161
Panels: P1, P2
Controls: C1..C6

+-----------------------+-----------------------+
! P1                          ! P2                         !
!                              !                              !
! C1                         ! C4                         !
! C2                         ! C5                         !
! C3                         ! C6                         !
!                              !                              !
+-----------------------+-----------------------+

Loop 1: C1 -> C2 -> C3 -> C1 (looping with tab key)
Loop 2: C4 -> C5 -> C6 -> C4
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:Astral100
ID: 12307167
I believe alex meant something else.
The problem is just about setting TabStop property to false in the components you don't want to cycle through.
Here I wrote a procedure which should take care of everything for you:

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    Panel2: TPanel;
    Label2: TLabel;
    Edit2: TEdit;
    Button2: TButton;
    procedure Panel1Enter(Sender: TObject);
    procedure Panel2Enter(Sender: TObject);
  private
    { Private declarations }
    procedure SetCanCycleThroughControl(Cntrl:TWinControl;CanCycle:Boolean);
//Cntrl - control containing all childs that should (or shouldn't) be cycled through
//CanCycle - allow, dissallow cycling though the controls
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SetCanCycleThroughControl(Cntrl:TWinControl;CanCycle:Boolean);
Var
i       :Integer;
begin
  for i:=0 to Self.ComponentCount-1 do begin
    if Self.Components[i] is TWinControl then
      if TWinControl(Self.Components[i]).Parent=Cntrl then
        TWinControl(Self.Components[i]).TabStop:=CanCycle;
  end;
end;

procedure TForm1.Panel1Enter(Sender: TObject);
begin
  SetCanCycleThroughControl(Panel1,true);
  SetCanCycleThroughControl(Panel2,false);
end;

procedure TForm1.Panel2Enter(Sender: TObject);
begin
  SetCanCycleThroughControl(Panel1,false);
  SetCanCycleThroughControl(Panel2,true);
end;

end.

Now, using SetCanCycleThroughControl procedure you can indicate any Panel (or even any TWinControl descendant) and allow (dissallow) cycling through all of it's child components using TabStop property.
For example - in the Panel1.OnPanelEnter event you indicate that all childs of that panel1 can be cycled through and of panel2 - cannot. Reversed for the Panel2.OnPanelEnter event.
0
 
LVL 2

Author Comment

by:__alex
ID: 12307197
Ok, got it. Thanks!
0
 
LVL 2

Author Comment

by:__alex
ID: 12307233
@Astral100
Sorry, but I closed the question before your comment appeared. Thank you anyhow!
0
 

Expert Comment

by:Astral100
ID: 12307270
Alex, could you please clarify which solution did you use?
Mine - Astral100 or calinutz's?

Your answer goes after my post, but the points go to the calinutz.
Could you clarify things a bit?
0
 

Expert Comment

by:Astral100
ID: 12307278
Ok, I see now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now