Solved

Change The Focus from Forms

Posted on 2002-06-05
38
171 Views
Last Modified: 2010-04-04
Hi there,
I'm developing an application but i've got the following problem:

This is the cenario:

1. You open the application and you get a Splash Screen,
   (Let's call it SpashForm)
2. It then goes to another form called PasswordDlg.

3. When you enter the right Password, it goes to the main form.

(The Problem Comes here)

4. From the main form you minimize to the TRAY, which contains a Popup menu with Open and Exit.

Now when you click on open i want the PasswordDlg form to come out and ask you for the Password again....and so on..

My Problem is that the PasswordDlg form shows up but cannot write on it, because it is not focused.

What can i do to make it work please?

Thanks

Sfern
0
Comment
Question by:sfern
  • 24
  • 10
  • 2
  • +1
38 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
soemthing like

pwform.show;
pwform.bringtofront;
pwform.setfocus;

meikl ;-)
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
Show actually does call bringtofront :)

procedure TCustomForm.Show;
begin
  Visible := True;
  BringToFront;
end;

so there is no need for BringToFront :)
also use Windows.SetFocus(pwForm.Handle);
0
 

Author Comment

by:sfern
Comment Utility
The main form is still there and when pwform shows up it works like it's disabled and will not let me write the password on the TEdit component, or close the form or anything :-(

Sfern
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
? looks like as you show your mainform modal

lee,
thanks for the look into the vcl-source,
but sometimes a call twice works better

meikl ;-)
0
 

Author Comment

by:sfern
Comment Utility
Still will not work :-(

Sfern
0
 

Author Comment

by:sfern
Comment Utility
It's now getting there but when i insert the write password
(e.g) if....Form1.show
else
.....
I got an error saying (Cannot Forcus a disabled or invisible window :-(

Sfern
0
 

Expert Comment

by:stohanzl
Comment Utility
Probe using API function :

SetActiveWindow(pwform.handle);

:o)
0
 

Author Comment

by:sfern
Comment Utility
It only works when i say: if....then Form1.Showmodal
else....

.....etc

And this brings back my previous problem :-(

Sfern
0
 

Author Comment

by:sfern
Comment Utility
Now it does'nt do anything when i insert the password :-(

this is the code for PasswordDlg Form:

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
If Edit1.text=Memo1.text then SetActiveWindow(Form1.handle)

else
MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
Edit1.Clear;
Edit1.SetFocus;
end;
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
stohanzl,

even if you state
>Probe using ...
then use a comment rather than an answer

thanks

meikl ;-)
0
 

Author Comment

by:sfern
Comment Utility
NOW...if i use:

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
If Edit1.text=Memo1.text then form1.showmodal

else
MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
Edit1.Clear;
Edit1.SetFocus;
end;

Then it will go to the main form but will not let me insert the password when i call back PasswordDlg form from the tray :-(

Sfern

0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
btw. i'm a bit confused,

could you explain how and
in which order you create and show your forms?
0
 

Author Comment

by:sfern
Comment Utility
NOW...if i use:

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
If Edit1.text=Memo1.text then form1.showmodal

else
MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
Edit1.Clear;
Edit1.SetFocus;
end;

Then it will go to the main form but will not let me insert the password when i call back PasswordDlg form from the tray :-(

Sfern

0
 

Author Comment

by:sfern
Comment Utility
Sorry, it still does not work
0
 

Author Comment

by:sfern
Comment Utility
OK,

1. You open the application and get a SplashForm, which after goes to another form called PasswordDlg, then if
you enter the right password it goes to Form1, which it the main form, on it, if you minimize the main form it goes to the Tray.
When you right click on the TrayIcon...It calls back the PasswordDlg form, prompting you to enter the password but when the PasswordDlg is shown it doesn't let me do anything, it's like disabled but not greyed.

Sfern

0
 

Author Comment

by:sfern
Comment Utility
This is the code from the PasswordDlg that checks the password:

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
If Edit1.text=Memo1.text then form1.showmodal

else
MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
Edit1.Clear;
Edit1.SetFocus;
end;
0
 

Expert Comment

by:stohanzl
Comment Utility
How do you CREATE the Pwd... dialog.. :
Pwd := TPwd.Create(Self)???


In this Case I think is better use Pwd := TPwd.Create(Application);

Probe IT...
0
 

Author Comment

by:sfern
Comment Utility
This is the code from the PasswordDlg that checks the password:

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
If Edit1.text=Memo1.text then form1.showmodal

else
MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
Edit1.Clear;
Edit1.SetFocus;
end;
0
 

Author Comment

by:sfern
Comment Utility
Any Ideas please?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:sfern
Comment Utility
The password is loaded from an eternal file but it's really calling back the PasswordDlg form that's giving me the headache

Sfern
0
 

Author Comment

by:sfern
Comment Utility
What about if on minimzing the Main Form i kill it...would that work?

Sfern
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
well ok, you call form1.showmodal
that means this form1 must be closed
before any other form can get the focus.

also just use
form1.close
before
you show the passwordform
(the passwordform is the logical application-mainform,
i guess)

meikl ;-)
0
 

Author Comment

by:sfern
Comment Utility
What about if on minimzing the Main Form i kill it...would that work?

Sfern
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>What about if on minimzing the Main Form i kill
>it...would that work?

i guess yes,
but instead of kill a simple close should do it also,
so you don't need to recreate the form again

meikl ;-)

0
 

Author Comment

by:sfern
Comment Utility
What about if on minimzing the Main Form i kill it...would that work?

Sfern
0
 

Author Comment

by:sfern
Comment Utility
I'm gonna have to take off the code on the main form OnCloseQuery otherwise it's not gonna work properly :-/

Sfern
0
 

Author Comment

by:sfern
Comment Utility
OK, i'm gonna have to change some code here

sfern :-/



0
 

Author Comment

by:sfern
Comment Utility
But this will mean that i would have to write some code to detect if windows is shutting, in order to prompt with a dialog

sfern

0
 

Author Comment

by:sfern
Comment Utility
I'm basically writting a folder locking application, which detects shutdown, and checks internet connection because if the folder is locked it stops any windows based viruses from infecting the stuff insterted there...It also stops deleting, copying, renaming etc...just giving it final touches :-/

sfern
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
Comment Utility
>I'm gonna have to take off the code on the main form >OnCloseQuery otherwise it's not gonna work properly

use a flag (a boolean var) which determines, if the form is closed by user or closed by applcation logic like


type tform1 = ....
       public
          fpwshow : Boolean; //defaults to false
     ...


procedure tform1.closequery...
begin
  canclose := fpwshow;
  if not canclose then
  begin
    //do your checks
  end;
end;

.....
in your popupmenuclick-procedure use something like this

....
  form1.fpwshow := true;
  form1.close;
  pwform.show;
.....

hope this helps

meikl ;-)
0
 

Author Comment

by:sfern
Comment Utility
I'm basically writting a folder locking application, which detects shutdown, and checks internet connection because if the folder is locked it stops any windows based viruses from infecting the stuff insterted there...It also stops deleting, copying, renaming etc...just giving it final touches :-/

sfern
0
 

Author Comment

by:sfern
Comment Utility
OK, meikl...i'll do that :-)
0
 

Author Comment

by:sfern
Comment Utility
Thanks all for your time.
I've managed to sort it out and
Thanks kretzschmar for your time and idea on the onclose situation.

Thanks again and BFN

Sfern :-)
 
0
 

Author Comment

by:sfern
Comment Utility
Thanks all for your time.
I've managed to sort it out and
Thanks kretzschmar for your time and idea on the onclose situation.

Thanks again and BFN

Sfern :-)
 
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hope it works

if you do this circular,
then the flag must be set to false again

this you can do in your password-routine like

procedure TPasswordDlg.OKBtnClick(Sender: TObject);
begin
  If Edit1.text=Memo1.text then
  begin
    form1.fpwshow := false;
    form1.showmodal
  end
  else
  begin
    MessageDlg('You have enter a wrong password!', mterror, [mbOK], 0);
    Edit1.Clear;
    Edit1.SetFocus;
  end;
end;


meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
well, glad to helped you
meikl ;-)
0
 
LVL 12

Expert Comment

by:Lee_Nover
Comment Utility
wow .. 35 posts :)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
yep, my inbox was also full :-))
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

9 Experts available now in Live!

Get 1:1 Help Now