Recent

Author Topic: What's wrong with my code II / dynamically created checkboxes and Tabstop  (Read 6095 times)

hy

  • Full Member
  • ***
  • Posts: 224
See the attached project.
I am having a form (1) with checkboxes that have been inserted in the IDE. TAB-Movement works perfect.
If you click on the button labelled "click me" another form (2) is opened. This form creates checkboxes and comboboxes dynamically (I don't know at compile time how much I will actually need - though the example is hardcoded).

If you press TAB in the second form only the first  two controls are getting the focus.
_____
***hy

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #1 on: November 13, 2014, 05:13:16 pm »
Not for me: Windows XP 32 bits, Lazarus 1.2.6.

Anyway, as far I can see the "Taborder :=" is useless in your case (i.e. always set to the by-default value -1). It seems it's only taken in account after the Windows control is "really" created.

So you could make a try by setting it after the "parent :=" instruction, like:
Code: [Select]
         parent := pnlMainOperate;
         TabOrder := i *2 shl 1;
...
         parent := pnlMainOperate;
         TabOrder := i shl 1 + 1;

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #2 on: November 13, 2014, 05:18:18 pm »
Plus, your tabulation order computation is wrong (i.e. not the same)
Code: [Select]
TabOrder := i *2 shl 1;
  and
TabOrder := i shl 1 + 1;

You should have:
Code: [Select]
TabOrder := i shl 1;
  and
TabOrder := i shl 1 + 1;
« Last Edit: November 13, 2014, 05:20:43 pm by ChrisF »

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #3 on: November 13, 2014, 05:25:44 pm »
Thanks ChrisF. But If I change the order of inserting the control  (setting parent respectively) and setting TabOrder it doesn't alter the behaviour. The other thing you mentioned is a typo (resulting from downsizing the Problem to the relevant stuff). I fixed it, but it didn't change the erroneous behaviour.
_____
***hy

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #4 on: November 13, 2014, 06:09:54 pm »
I can see in your signature that you are using a Linux OS.

I guess this is probably why there is a difference between us (as I've written before, your code is working for me with Windows).

You can eventually try to also set the TabStop option to true after the SetParent instruction. Though I'm not even sure that the controls are created for the Linux versions as for the Windows version (i.e. when the SetParent instruction is called).

Curiously, you are saying that only the first 2 "dynamics" controls can be reached with the tabulation. And you have 2 "fixed" controls in your second form (i.e. 2 pushbuttons with tabulation order = 0 and 1). It may eventually be related.

You could eventually add 2 other dummy pushbuttons, for instance, with tabulation order = 2 and 3, and see if the first 4 "dynamics" controls can now be reached with the tabulation. Just for a test purpose...

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #5 on: November 13, 2014, 06:28:12 pm »
Hi ChrisF,
that is very kind of you to be so creative though you can not reproduce the problem.

But I am VERY sorry to have to tell you that it didn't work out. I changed the code to four dynamic items and four Buttons (also tried TEdit and others).
What happens is:
1.) On startup of form2 the first dynamic item is focused correctly due to
Code: [Select]
activeControl := TCheckBox(self.pnlMainOperate.Controls[0]);
2.) Pressing <TAB> focusses the (dynamically created) Combobox with Taborder:=2 [as everyone would expect]
3.) Pressing <TAB> again focusses nothing
3.) Pressing <TAB> again focusses the (dynamically created) Tcheckbox with Tab-Order = 0
Note: you can not reach the buttons via TAB at all!

Now the same with <shift-TAB>:
1.) On startup of form2 the first dynamic item is focused correctly due to
Code: [Select]
activeControl := TCheckBox(self.pnlMainOperate.Controls[0]);2.) Pressing <SHIFT-TAB> focusses the last button in the lower panel (with the max Taborder in the lower panel)
2.) Pressing <SHIFT-TAB> focusses the previous button in the lower panel
... and so on.
After the first button in the lower panel is reached the LAST DYNAMICALLY created TWIncontrol is focussed.

So far so good. But pressing <SHIFT-TAB> again does not set the focus to the previous element but to nothing at all or something invisible.
Pressing <SHIFT-TAB> again sets the focus to the Last button in the lower panel.
_____
***hy

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #6 on: November 13, 2014, 06:39:25 pm »
I just found out that everything (seems to) work fine when the dynamically created controls are NOT on a TPanel.
So probably the TPanel screws the behaviour of navigating on the form (in WS gtk2).
But anyway I need a solution for this.
_____
***hy

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #7 on: November 13, 2014, 06:54:09 pm »
This might do the job for you
Code: [Select]
SelectNextprobably under the exit event
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #8 on: November 13, 2014, 07:17:11 pm »
Thanks never I will give it a try I filed a bug report.
actually it's the TPanel which screws it up. If I put the items onto the form directly or if I use a groupbox everything works as expected.
_____
***hy

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #9 on: November 13, 2014, 07:23:00 pm »
SelectNext doesn't work either.
Forward <TAB> selects only the comboboxes (for whatever reason)
backward <SHIFT - TAB> doesn't do anything
_____
***hy

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #10 on: November 13, 2014, 07:45:08 pm »
NEVER: You are right SelectNext saved me the day.
On my first try I've put it into the keydown event and forgot to set key:=0
Now that Ive done it it works.
Thanks a lot.
_____
***hy

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #11 on: November 13, 2014, 08:22:46 pm »
glad you get the job done
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #12 on: November 13, 2014, 09:28:53 pm »
Isn't there some automation with the tab order? No control can have the same TabOrder, so at some point it compares to rest of the controls and sets the value to something new.

So if i were to guess, you start by just creating the checkboxes and not touching taborder at all yet. Then afterwards go through them from last to first order setting the TabOrders.

hy

  • Full Member
  • ***
  • Posts: 224
Re: What's wrong with my code II / dynamically created checkboxes and Tabstop
« Reply #13 on: November 13, 2014, 09:30:03 pm »
The TabOrder is in perfect state after creating. I double checked it. But thanks for trying.
_____
***hy

 

TinyPortal © 2005-2018