Solved

Strange hang on Windows NT

Posted on 1998-12-28
11
330 Views
Last Modified: 2010-04-04
In a special case, I am making my main window disabled, minimzed and invisible) and then showing another form which looks like the main form to the user. This is shown in a ShowModal state. Everything works OK on Windows 95. But, on Windows NT, the application hangs at the point where application.processMessages is called. I don't have NT but found this by a debug version of my application which was tested by a user on NT. By a previous version, I know that this problem didn't occur when the main window was only disabled and minimized.

Anyone can confirm or explain this strange behavior on Windows NT 4 sp3? That is, if the main window is made invisible, it can cause processMessages to never return?

Thanks,
Sanjay
0
Comment
Question by:skanade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1353386
Hmmm. Do you disable, minimize and hide the real main window? Why minimizing AND hiding? I think, you should only hide it. It doesn't matter then if it is minimized or not. And ShowModal of the other form will disable the real main window for you.
However, I don't know if that would fix your problem.
No, I can't explain this behaviour. I didn't have any problems like this yet. Perhaps you can post some code? Escpecially the lines with the PostMessage...

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1353387
as madshi said what are the lines before applicaion.processmessages;  

Regards Barry
0
 

Author Comment

by:skanade
ID: 1353388
Well, I can email you a complete test project (245K zipped) for Delphi 3. Just send email to me at 'skanade@superb.net.' This project is rather interesting. If the name of the EXE is SETUP.EXE, it works as a setup program, hence the need to hide the main window. Why didn't I use traditional setup stuff? I have some special processing, and this way, I just add about 40K to the main executable reducing the total distributable size. Of course, it is suitable for small utilities only, no shared files, no databases.

Thanks,
Sanjay
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Madshi
ID: 1353389
The complete project would not help me very much, because (1) I've not the time to look at such a big project (sorry) though it really sounds interesting and (2) I don't have winNT to test something...  :-(
But perhaps I could see something if you would only post the function with the processMessages...

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1353390
i've just tried it and had no troubles at all????
win95,win98 and nt although no service pack on nt
ive posted some code for madshi to look at i dont know whats wrong with it sorry :-)

unit main;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMainWin = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    fsetup: boolean;
  public
     constructor Create(Owner: TComponent); override;
     procedure DoIdle(Sender: TObject; var Done: Boolean);
  end;

var
  MainWin: TMainWin;
implementation
{$R *.DFM}
uses sksetup;

//*****************************
constructor TMainWin.Create(Owner: TComponent);
begin
  //Find out if it is SETUP that we need
  fsetup := false;
  if ((ParamCount > 0) and (UpperCase(ParamStr(1)) = ':SETUP'))
     or
     (UpperCase(ExtractFileName(Application.ExeName))
        = 'SETUP.EXE') then
    fSetup := true;
  inherited create(Owner);
end;

//*****************************
procedure TMainWin.DoIdle(Sender: TObject; var Done: Boolean);
begin
  Application.OnIdle := nil;
  if (fSetup) then
  begin
    //The following code uses the form as a modal form
    with TSKMainForm.create(self) do
    try
      visible := false; //a must, otherwise error message
      showModal;
    finally
      free;
    end;
    close;
    exit;
  end;
end;

//*****************************
procedure TMainWin.FormCreate(Sender: TObject);
begin
  if (fSetup) then
  begin
    enabled := false;
    windowstate := wsMinimized;
    visible := false;
    application.processMessages;
    Application.OnIdle := DoIdle;
    exit;
  end;
  //other processing for normal application here
end;

//*****************************
procedure TMainWin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if (fSetup) then
    exit;
  //other normal app's close processing, registry writing, etc.
end;

end.

0
 

Author Comment

by:skanade
ID: 1353391
Were you able to proceed till Copy Files and complete the Setup? It hangs in the processMessages call in the copyFiles operation.

Thanks,
Sanjay
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353392
Hmm. I don't like this kind of construct. There are two things that seem to be not very clean.
(1) In the TMainWin.Create constructor you use the private variable fSetup before creating the form (by calling inherited). Normally you should do this the other way round, because normally the inherited call is responsible for allocating the new form's object including the fSetup variable.
(2) This OnIdle/ProcessMessages construct is quite a roundabout way.

My suggestion:

This is the important part of the Application.Run code: (Remember, Application.Run is called in your dpr file.)

      if FShowMainForm then
        FMainForm.Visible := True;
      repeat
        HandleMessage
      until Terminated;

So you replace the Application.Run call in your dpr file with the following code:

  if ((ParamCount > 0) and (UpperCase(ParamStr(1)) = ':SETUP')) or
     (UpperCase(ExtractFileName(Application.ExeName)) = 'SETUP.EXE') then begin
    with TSKMainForm.create(self) do
      try
        visible:=true;
        repeat Application.HandleMessage until Application.Terminated;
      finally free end;
  end else begin
    MainWin.visible:=true;
    repeat Application.HandleMessage until Application.Terminated;
  end;

Now you can delete all this onIdle/fSetup/... stuff.
I think that should fix your problems.

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1353393
madshi
good idea  

skanade
yes it copied files but as you know it's not stable so try  what madshi said ,i think he's hit the right note on this one
Regards Barry

ps..as an after thought  maybe after you have made changes ask another question for small amount of point's asking if people (with nt sp4)would be able to try your prog for you i'll bet one or 2 will test for you as madshi dont have nt and i dont have service pack on mine.
 
0
 

Author Comment

by:skanade
ID: 1353394
Many thanks to both of you! Madshi, if you will post a dummy answer, I will award the points. And for all the trouble both of you have taken, I will send you a complimentary registration offer to my shareware utility whether your solution works or not. I have Barry's address but don't have Madshi's. So, Madshi, if you would like to avail of my offer, please send email to my address posted above.

BTW, I have enough testers on NT (my users of the previous version). So, no problem there. That's the way I got to know of the hang anyway.

Regards,
Sanjay
0
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 1353395
Thank you Sanjay, thank you Barry...  :-)

My eMail is "Mathias.Rauen@gmx.de"

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1353396
skanade
 i'll take you up on that and hope your troubles are over now
Regards Barry
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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