Solved

Moving trough components

Posted on 2002-05-06
4
150 Views
Last Modified: 2010-04-04
I have app with a few forms with lot of controls for data input (text or numbers). Is there any simple way to switch amongst them (to make them active) while entering data. Tab is clumsy becouse of large number of controls. I would need something like arrow keys that moves focus to nearest component in any direction. Perhaps someone have code already writen?
0
Comment
Question by:TomazB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Expert Comment

by:God_Ares
ID: 6991197
use setfocus...

edit1.SetFocus;

e.g. you must enter a valid zip in edit1 to go tho the next thing


procedure jada1.OnkeyUp(jadajadajada)
Begin
  if length(edit1.Text)=4 {and ValidateZip(Edit1.text)} then button1.SetFocus;
end;

or with the arrows

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var   d,e:Tcontrol;
 i:integer;
begin
  if ssShift in shift      then
  Begin
    d := TControl(sender);
    for i:=0 to d.parent.controlcount-1 do
      find best one fitting to key by using d.left en d.top
    e.setfocus;
   if key = vk_up then
  end;
end;

0
 
LVL 7

Accepted Solution

by:
God_Ares earned 50 total points
ID: 6991238
an example of going to a control above
do the other 3 yourself..

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var  s:Tcontrol;
     o,b:TwinControl;
  i,x,y:integer;

begin
    s := TControl(sender);
    if key = vk_up then
    Begin
      b:=nil;
      x:=1000; y:=1000;
      for i:=0 to s.Parent.ControlCount-1 do
      Begin
       if s.InheritsFrom(Twincontrol) then
       Begin
         o := TWincontrol(s.Parent.Controls[i]);
         if s.top > o.Top then //found a control above currrent
         begin
           if abs(s.Left - o.Left) < x then
           Begin
             x:=abs(s.Left - o.Left);
             y:=o.Top;  //store component's pos
             b := TWincontrol(s.Parent.Controls[i]);
           end;
         end;
       end;
      end;
      if b<> nil then b.setfocus;
    end;
end;
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6991254
this works great for edit's and memo's
0
 

Expert Comment

by:SpideyMod
ID: 8280693
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

617 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