Solved

Delphi Programming question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't connect to Outlook via TOutlookApplication component 15 120
how to draw animated progressbar in Tvirtualstringtree 5 117
Simple Delphi Question 9 83
Base1 Encode/Decode 3 68
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

15 Experts available now in Live!

Get 1:1 Help Now