Solved

Tab order

Posted on 2004-10-14
9
235 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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