0

I am being hounded to make a Delphi VCL form configurable so that different users will tab through fields in different orders and have access to different fields. I keep telling everyone that this is a BAD IDEA but they simply aren't hearing anything that they don't want to hear.

My question is this:

Is there an existing Delphi component that will allow me to do this without having to have OnEnter / OnExit events for every field on the form? Ideally the component would also intercept KeyPress events to allow for the Tab / Shft-Tab problem.

I have tried to do this on a limited basis in the past and found to be a nightmare so any suggestions that might make my life easier are appreciated.

1 Answers1

3

Regarding the tabbing, the way to do this is through the TabOrder property. If different users need different tab orderings, then you'll need to set TabOrder at runtime.

Likewise, to control access, you will need to set the Enabled or Visible properties at runtime to control that.

If TabOrder doesn't cut it, as you indicate in the comments, then you'll need to listen for CM_DIALOGCHAR messages sent to the form. Test the CharCode member of the TCMDialogKey record and if it is VK_TAB set the focus as you please.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • You should also mention the Enabled/Visible property for the fields without access :) - just for a complete answer – Sir Rufo Aug 26 '14 at 18:23
  • @SirRufo I don't quite follow what you mean. – David Heffernan Aug 26 '14 at 18:30
  • The question is about different tab order **and** access to different fields - *different users will tab through fields in different orders and have access to different fields* – Sir Rufo Aug 26 '14 at 18:48
  • Sadly, it isn't as simple as just setting the tab order. This is a very complex form with components in frames and tab sheets so you can't just start numbering the tab order at 1 and work your way up. Each frame and tab sheet has its own tab order and we somehow have to be able to skip from field 3 of 6 in one frame to field 2 of 6 in a different frame. No amount of fiddling the tab order will do that. As for making fields not visible it gives the form a gap toothed appearance that is not very appealing. I'm pushing for different forms for different classes of users, but so far no joy. – sboydlns Aug 26 '14 at 20:13
  • BTW, just to make life more interesting they want to skip certain fields based on data entered into other fields. It's really kind of a nightmare. – sboydlns Aug 26 '14 at 20:15
  • These are new requirements. All the same, tab order can do the trick if you flatten the parent/child relationships. If you don't want to make controls invisible, don't. Up to you. OnEnter/OnExit won't help. They are a consequence of focus change. And not always related to TAB. – David Heffernan Aug 26 '14 at 20:23
  • If you wanna skip certain fields based on data then simply change the TabStop properts to False at the runtime. But jumping from one field on one tab to field on another tab that is nowhere easy task. Tab order system wasn't designed for such scenarios. – SilverWarior Aug 26 '14 at 21:03
  • I'll look into CM_DIALOGCHAR and see where that leads me. Thanks. – sboydlns Aug 27 '14 at 17:21