Link to home
Start Free TrialLog in
Avatar of sfern
sfern

asked on

Change The Focus from Forms

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
Avatar of kretzschmar
kretzschmar
Flag of Germany image

soemthing like

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

meikl ;-)
Avatar of Lee_Nover
Lee_Nover

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);
Avatar of sfern

ASKER

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
? 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 ;-)
Avatar of sfern

ASKER

Still will not work :-(

Sfern
Avatar of sfern

ASKER

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
Probe using API function :

SetActiveWindow(pwform.handle);

:o)
Avatar of sfern

ASKER

It only works when i say: if....then Form1.Showmodal
else....

.....etc

And this brings back my previous problem :-(

Sfern
Avatar of sfern

ASKER

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;
stohanzl,

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

thanks

meikl ;-)
Avatar of sfern

ASKER

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

btw. i'm a bit confused,

could you explain how and
in which order you create and show your forms?
Avatar of sfern

ASKER

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

Avatar of sfern

ASKER

Sorry, it still does not work
Avatar of sfern

ASKER

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

Avatar of sfern

ASKER

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;
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...
Avatar of sfern

ASKER

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;
Avatar of sfern

ASKER

Any Ideas please?
Avatar of sfern

ASKER

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

Sfern
Avatar of sfern

ASKER

What about if on minimzing the Main Form i kill it...would that work?

Sfern
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 ;-)
Avatar of sfern

ASKER

What about if on minimzing the Main Form i kill it...would that work?

Sfern
>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 ;-)

Avatar of sfern

ASKER

What about if on minimzing the Main Form i kill it...would that work?

Sfern
Avatar of sfern

ASKER

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

Sfern
Avatar of sfern

ASKER

OK, i'm gonna have to change some code here

sfern :-/



Avatar of sfern

ASKER

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

Avatar of sfern

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sfern

ASKER

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
Avatar of sfern

ASKER

OK, meikl...i'll do that :-)
Avatar of sfern

ASKER

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 :-)
 
Avatar of sfern

ASKER

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 :-)
 
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 ;-)
well, glad to helped you
meikl ;-)
wow .. 35 posts :)
yep, my inbox was also full :-))