Solved

Delphi Programming question

Posted on 1997-07-30
2
188 Views
Last Modified: 2010-04-04
Why does this program sometimes die?

In the OnCreate for my main form there are a number of conditions that can arise where I want to display a message and shut the program down. In D2 you can do this neatly by setting the ShoMainFor varaible, however in D1 An Application.Terminate or halt results in an ugly flash of the main form prior to the message displaying. The objective was to get rid of this flash.

I took the main form out of the AutoCreate list and create it in my project source (see below), if a shutdown condition occurs I set the class variable <abortApp> to true. I then test this variable and if it's kosher I show the form. I then run Application.HandleMessage in a loop until the user closes the form.

This has been working in the field no problems. Now a user is reporting a problem which occurs every week or so, where the program show in the task list but the main form never actually shows. I have been unable to locate the source of this problem, but wonder if the code below may be guilty?

If anyone can shed some light on this that would be great.

Thanks.

Tom.

program Product1;

uses
  Classes,
  Stdctrls,
  Forms,
  Menus,
  Utils,
  ExtCtrls,
  Punch in 'form1.PAS' {frmForm1},

{$R *.RES}

begin
  { using nil means Application doesn't own the form and so
    we free it explicitly }
   frmForm1 := TfrmForm1.Create(nil);
   try
      if not frmForm1.abortApp then begin
         frmForm1.Show;
         repeat
            Application.HandleMessage;
         until not frmForm1.Visible;
      end;
   finally
      frmForm1.Free;
   end;
end.
0
Comment
Question by:tomcorcoran
[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
2 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 90 total points
ID: 1340218
Didn't read all your question, but if i understood and you want to check some thing prior to displaying the form and prevent the flashing, then write every thing you need in the dpr as follows:

program Project1;

uses
  Forms,windows,......
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}
var ......
begin
  if something then
    Application.Terminate
  else
  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.

0
 

Author Comment

by:tomcorcoran
ID: 1340219
Thanks. The problem was that I needed to possibly kill it after running the form's OnCreate. My above code actually works well and I found the problem to be elsewhere - in the form's OnCreate it was periodically getting stucl in a loop due to a cyclical clipper index, so all's well now. Thanks. Tom.
0

Featured Post

Industry Leaders: 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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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