Recent

Author Topic: Form not hiding when using form1.hide  (Read 4306 times)

timcs

  • Full Member
  • ***
  • Posts: 213
Form not hiding when using form1.hide
« on: August 24, 2016, 01:51:51 pm »
hi

  My program has always being able to hide from view and I also add minimized and ShowinTaskbar=stNever , recently however I have added a function/procedure that is called from Form activate which checks to make sure that the database connection will work and while this has been added the problem has occurred.

What happens instead is that the form minimizes but the program does not move forward in the code, so to speak,until it has been maximized and then it hides and the program continues.
 
  I have probably gone a bit made with adding

 form1.WindowState:=wsMinimized;
   //do not show application in taskbar
   form1.ShowInTaskBar:=stNever;
  //hide the form
  form1.WindowState:=wsMinimized;
    form1.Hide;   

In all areas possible but to no avail. The function/procedure runs try except finally routines if this is any clue.

 I suspect it might have something to do with the form not be full visible ? but not sure how to get around this.

Thanks

TimCS

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: Form not hiding when using form1.hide
« Reply #1 on: August 24, 2016, 01:58:38 pm »
Don't use OnActivate for such task. Check the database connection in "OnCreate" and store the result in a "DatabaseOK: Boolean" value. As far as I recall the OnActivate is only triggered when the form is actually activated - hiding the form for obscure reasons should disable the OnActivate from being called until the form is restored and displayed on screen.

timcs

  • Full Member
  • ***
  • Posts: 213
Re: Form not hiding when using form1.hide
« Reply #2 on: August 24, 2016, 02:01:50 pm »
Thanks for the reply Fungus,

  If I move the database check in onCreate, will this mean that the form hide will need to be called from somewhere else ? I would have thought it would not work in OnCreate would it? Also I will have to move other calls from form activate to On Create as they all are required to work with the database connection check.


Thanks again

TimCS

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: Form not hiding when using form1.hide
« Reply #3 on: August 24, 2016, 02:37:20 pm »
You cannot change the forms visibility in an OnHide/OnShow/OnActivate event. If you check the database in OnActivate and call Hide after that, you are really doing something shady. Also you might consider (in the *.LPR file) to set:

Code: Pascal  [Select][+][-]
  1.   ...
  2.   Application.Initialize;
  3.   Application.ShowMainForm=False;
  4.   ...
  5.  

timcs

  • Full Member
  • ***
  • Posts: 213
Re: Form not hiding when using form1.hide
« Reply #4 on: August 24, 2016, 07:12:38 pm »
You cannot change the forms visibility in an OnHide/OnShow/OnActivate event. If you check the database in OnActivate and call Hide after that, you are really doing something shady. Also you might consider (in the *.LPR file) to set:

Code: Pascal  [Select][+][-]
  1.   ...
  2.   Application.Initialize;
  3.   Application.ShowMainForm=False;
  4.   ...
  5.  

Thanks again Fungus, I am so rusty with this at the moment , it has been a while so sorry for the "shady" coding it should be something I should know as well.

This is what happens when I try and code in different languages :)

Thanks

TimCS

timcs

  • Full Member
  • ***
  • Posts: 213
Re: Form not hiding when using form1.hide
« Reply #5 on: August 25, 2016, 06:28:51 pm »
Just wanted to check that I can do the following if I make calls etc from On Create:

From calling the connectdatabase procedure/function this will also need to be able to display a messageDLG if it cannot connect, will this work from On Create?

I would also need to call an IP address function as well to get the PCs IP address would this also work from on Create ?

Finally I need to check for parameters called to my program which I have always done in Form Activiate can this be done in On Create?

Sorry again for the stupid questions there was a time when I would know the answer to the above not sure where that knowledge has gone too......

Thanks

TimCS

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: Form not hiding when using form1.hide
« Reply #6 on: August 25, 2016, 07:14:29 pm »
Yes, you can do all of that in OnCreate :-)

timcs

  • Full Member
  • ***
  • Posts: 213
Re: Form not hiding when using form1.hide
« Reply #7 on: August 25, 2016, 09:28:27 pm »
Yes, you can do all of that in OnCreate :-)

Great thanks again Fungus for your help

 

TinyPortal © 2005-2018