Solved

Strange hang on Windows NT

Posted on 1998-12-28
11
313 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 156
Delphi Dbf export problem to a Visual Foxpro application 6 187
error 1.1 400 Bad request idhttp delphi 18 86
Delphi...Split view - idea? 1 67
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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