Solved

Strange hang on Windows NT

Posted on 1998-12-28
11
302 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
  • 4
  • 4
  • 3
11 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
as madshi said what are the lines before applicaion.processmessages;  

Regards Barry
0
 

Author Comment

by:skanade
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:skanade
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you Sanjay, thank you Barry...  :-)

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

Regards, Madshi.
0
 
LVL 17

Expert Comment

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

10 Experts available now in Live!

Get 1:1 Help Now