Solved

Moving trough components

Posted on 2002-05-06
4
147 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now