Solved

How to change focus from one form to another

Posted on 1998-07-06
4
159 Views
Last Modified: 2010-04-04
I expected this to be easy but have been struggling with it.  My application has two forms - one AppBar docked to the bottom of the screen and another one maximized, so the two are visible at all time. The AppBar for has to be created first and then the other form is created. As a result the AppBar has the focus initially.  How can I make the other form (which has one Tedit on it) have the focus.  I have tried a few obvious things like Form1.Setfocus when OnShow, etc...
0
Comment
Question by:ymailhot
4 Comments
 
LVL 1

Expert Comment

by:michaue
ID: 1357209
Make Form1.ActiveControl = to the TEdit in the OnShow event of Form2 put the following

Form1.Show;

Hope it works

Elfrieda :)
0
 

Expert Comment

by:LilitaN
ID: 1357210
Try in AppBar.OnShow event set Screen.ActiveForm := form1

Lilita
0
 

Author Comment

by:ymailhot
ID: 1357211
Comment from LilitaN:  The Screen attribute is read only so the only way to bring the focus to a form is to use setfocus. This was the first thing I tried (AppBar OnShow Event with Form2.SetFocus). For some reason the focus remains on the appbar.

Solution from Michaud: I tried that too. I get the message cannot focus on an invisible object or something like that.  I just went to try it again and now I don't even see the objects from Form2 in ActiveControl of AppBar.

Thank you.
0
 
LVL 3

Accepted Solution

by:
vladika earned 50 total points
ID: 1357212
I found two ways to solve your problem

1) If AppBar is MainForm, just set AppBar.Visible and Form1.Visible to TRUE.
After that AppBar created first and at once become visible,
then Form1 created and become visible too and FOCUSED.

2) set AppBar.Visible = False and write AppBar OnFormActivate handler
procedure TAppBar.FormActivate(Sender: TObject);
const First: Boolean = True;
begin
  if First then
  begin
    Form1.Show; // if first call then show Form1
    Windows.SetFocus(Form1.Handle); // ... and set focus
    First := False;
  end;
end;


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

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
Delphi: how to send PJL commands to printer 3 90
oracle global variables 4 63
Error E2158 compiling with Delphi XE10 Seattle 2 88
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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

17 Experts available now in Live!

Get 1:1 Help Now