Solved

Delphi Programming question

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

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.

Question has a verified solution.

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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 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