Solved

Moving trough components

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

20 Experts available now in Live!

Get 1:1 Help Now