Solved

Delphi Programming question

Posted on 1997-07-30
2
174 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

11 Experts available now in Live!

Get 1:1 Help Now