Solved

Tab order

Posted on 2004-10-14
9
233 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

18 Experts available now in Live!

Get 1:1 Help Now