Solved

Error Closing a Delphi Program

Posted on 2010-08-15
6
1,209 Views
Last Modified: 2013-11-23
A program I'm writing requires data from a flash drive, so I inspect removable drives for the file. If there's a removable drive and the file exists, no problems. If there is no no file, I'd like to provide a message to the user to install his data flash drive then re-start the app. After he clicks OK, the program terminates but AFTER it ends, I get a error (from Windows?)  :
    EInvalidOperation with message 'Cannot change visible in OnShow or OnHide'

I don't use an OnShow or OnHide anywhere in the app yet the problem persists. I have installed the code in a new, blank form and it works fine. But when add it to the "OnActivate" event of my
program it bombs after termination.

Any help would is appreciated. Thanks.

Ed
SDataFile := LocateDataFile;   

             //Expecting like 'F:\DatFile.bin'



if SDataFile = '' then begin

   showmessage('Data File NOT found. '+

               'Please insert your data flash drive and re-start);

   Application.Terminate;      {'close' produces the same error}

End;



//Problems get much worse if I wait for the flash drive even

//when it gets inserted and the TDriveComboBox is updated.

Open in new window

0
Comment
Question by:Ed-SSA
  • 3
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
I've tested your code and it doesn't raises any error. I used form's OnActivate. Are you using Form's event or Application event?
0
 
LVL 30

Assisted Solution

by:Marco Gasi
Marco Gasi earned 500 total points
Comment Utility
Tested with TApplicationEvent also: none error... Have you other secondary forms in your app? Or  procedure LocateDataFile calls and shows/hides some dialog or some form?
0
 

Author Comment

by:Ed-SSA
Comment Utility
That was fast - thank you.

Based on the fact that we both got the code to work on a fresh new form, I changed the basic set-up in the OnActivate event of the form. instead of;
             If not filefound then close;
 I start with
             if filefound then begin
               {the remainder of the event code here}
               else begin
                 showmessage('Insert data drive');
                 close;
              end;

I do sorta remember from 30 years ago, that bad juju can happen if you try to quit in the middle.

Thank you for your Help Marqus
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Glad you solved, but if the problem were that you think, should raise error even in a blank form, doesn't? I think there is something in LocateDataFile procedure or in some aother place that conflicts with Close statement. However, good bye
0
 

Author Comment

by:Ed-SSA
Comment Utility
marqus -

The first thing I did was to transfer the code to a new form, where it worked as expected. And now that I changed the way / order of code execution, it also worlks in my program - using LocateDataFile.

I agree there may still be a problem somewhere and wish I knew something about error trapping which I've always been able to avoid. A trip to the bookstore is in my near future -:)

Thanks for sticking araound. - Ed
0
 
LVL 3

Expert Comment

by:big_one01
Comment Utility
Check in the Delphi IDE menu:
Project-->Options
 In the Forms tab --> Autocreate forms:

Maybe you have some form that must not be there, then the form is autocreated and when you dont close o destroy that instance, then raise the error.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 69
Newbie Thread Programming 1 116
Delphi XE10 Round Image 2 48
Unable to start eclipse ? 17 82
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…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

744 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

17 Experts available now in Live!

Get 1:1 Help Now