Solved

Delphi Programming question

Posted on 1997-07-30
2
189 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

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 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