Delphi tab order
Asked Answered
O

3

9

The tab order on my form in Delphi (Embarcadero® Delphi® 2010 Version 14.0) is incorrect, which means the tab key skips to seemingly random items in the form.

However, when I go and change it in Delphi, it rearranges them for me, in the same incorrect order!

So, I decided to programmatically assign them:

procedure FixDelphiTabOrder;
begin
  Form2.ButtonClear.TabOrder := 2000;
  Form2.ButtonExport.TabOrder := 1900;
  Form2.ButtonNew.TabOrder := 1800;
  Form2.MaxFreq.TabOrder := 1700;
  Form2.MinFreq.TabOrder := 1600;
  Form2.Summary.TabOrder := 1500;
  Form2.Plot6dB.TabOrder := 1400;
  Form2.Plot3dB.TabOrder := 1300;
  Form2.Use_dBs.TabOrder := 1200;
  Form2.PlotPoints.TabOrder := 1100;
  Form2.PlotPhase.TabOrder := 1000;
  Form2.Prop8Value.TabOrder := 900;
  Form2.Prop7Value.TabOrder := 800;
  Form2.Prop6Value.TabOrder := 700;
  Form2.Prop5Value.TabOrder := 600;
  Form2.Prop4Value.TabOrder := 500;
  Form2.Prop3Value.TabOrder := 400;
  Form2.Prop2Value.TabOrder := 300;
  Form2.Prop1Value.TabOrder := 200;
  Form2.FilterType.TabOrder := 100;
  ShowMessage(IntToStr(Form2.Prop1Value.TabOrder));
end;

(I tried assigning it both backwards and forwards; it does the same thing.)

But this still doesn't work. The message box pops up with 7 instead of 100, every time. Something is consistently changing the order, but it's not my code.

Why is this, and is it possible to fix it?

This is for my A2 Computing Project

Orthoepy answered 16/1, 2012 at 14:24 Comment(1)
@David Consider it done. Sorry - got behind.Orthoepy
S
26

TabOrder is contiguous. The first control has TabOrder of 0. The next has TabOrder of 1 and so on. You cannot leave any gaps.

Whilst you can assign TabOrder programmatically, I personally find it easiest to use the GUI to do so. Right click on the form, or indeed on a container control, and select the Tab Order menu item. Then you will see a dialog like this:

enter image description here

You can use the arrow buttons to re-order, or you can simply drag items to re-order. It works reasonably well in my view but you must remember that controls which contain other controls (e.g. panels, tabsheets etc.) have their own tab order. For such a control you need to select that control, right-click and then modify the tab order for the children of that container.

Shorn answered 16/1, 2012 at 14:27 Comment(6)
Too much BBC Basic. I guess it means a lot of re-ordering if I want to add something new in.Orthoepy
Ah yes, the BBC Micro. I had a model B. REN 10, 10 seems to ring a bell!Shorn
If you're not using the Tag property of the components then you could assign your ad-hoc 'TabOrder' values to the Tag property and then create a procedure to programmatically set the tab order based on the tag values. You could then easily insert new components with intermediate tags and have the tab order procedure sort it out automatically.Clubby
Thank you. This fixed it and now my program is more usable.Orthoepy
@DavidHeffernan, I was expecting to see TOrchButton there.Hodges
@Hodges No need for TOrcButton. The standard VCL TButton does all that I need!Shorn
A
15

If I did understand you well, CnPack can help in design time.

Below you can see one feature. CnPack can show you the Tab Orders as you put the components in form. This can help when you have many edits, buttons or panels.
CnPack Display TabOrders in Designing Mode

Another feature is the button "Auto Set Tab Orders in the Form", that set the Tab Orders using the position of each controls to define it's Tab Order. See below the same form after pressed the button. "Auto Set Tab Orders in the Form" button

I find them extremely helping when designing big forms. Another option would be GExperts Tab Order screen that have the same "order by position" feature: enter image description here

Amphigory answered 16/1, 2012 at 18:17 Comment(1)
+1 very nice answer showing off two very useful and powerful toolsShorn
U
3

The way I set tab order is by selecting each component in the order you want the tab order, then cut the controls to the clipboard (CTRL-X), then paste (CTRL-V) them back again.

Unwished answered 17/1, 2012 at 1:44 Comment(1)
@FabricioAraujo - Actually, for few controls is quite a quick method. I will use it! If you have many I recommend indeed CNPackBrannan

© 2022 - 2024 — McMap. All rights reserved.