• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Strange hang on Windows NT

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
skanade
Asked:
skanade
  • 4
  • 4
  • 3
1 Solution
 
MadshiCommented:
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
 
intheCommented:
as madshi said what are the lines before applicaion.processmessages;  

Regards Barry
0
 
skanadeAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MadshiCommented:
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
 
intheCommented:
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
 
skanadeAuthor Commented:
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
 
MadshiCommented:
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
 
intheCommented:
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
 
skanadeAuthor Commented:
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
 
MadshiCommented:
Thank you Sanjay, thank you Barry...  :-)

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

Regards, Madshi.
0
 
intheCommented:
skanade
 i'll take you up on that and hope your troubles are over now
Regards Barry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now