?
Solved

Tab order

Posted on 2004-10-14
9
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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