Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Moving trough components

Posted on 2002-05-06
4
Medium Priority
?
156 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 150 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

824 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