Solved

Moving trough components

Posted on 2002-05-06
4
149 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 June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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