Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms will not close

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have a Delphi 7 program that has 32 Forms that are initializes at activation. There is a Main Menu to select one of 14 individual sub-programs. When a sub-program is selected, the next Form is called by ShowModal and the Main Menu Form is closed. Several of these programs display a Member Selection Form with a DBGrid that displays over 3,000 Members of an organization. When a selection is made of a specific member, ShowModal brings up the Data Entry Form for data entry or correction and the Member Selection Form is closed. At this point there is no problem. I can close the three Forms in reverse sequence.
Most of the time I need to make entry or corrections to several members’ data. To do this I will close the Data Entry Form and then select a new member from the Member’s Selection Form and repeat the process going back and forth between the Member Selection Form and the Data Entry Form. So far no there is problem; all of my data entries are completed successfully.
The problem is when I try to close the three Forms after multiple entries. When I close the Data Entry Form the Member Selection Form is displayed. When I try to close the Member Selection, it is closed and the Data Entry Form is again displayed. I cannot close either and cannot get back to the Main Menu. I have to re-boot to close the program.
How can I solve this problem?
 
Try creating your "Pop-up" forms from the module you are executing them from instead of initializing them with program startup like so(I think this is right; It has been soooo long since I have used Delphi; I have been using BCB since 2000):

Code:
procedure RunSubForm()
var SubForm:TForm1;
begin
  Application.CreateForm(TForm1, SubForm);
  SubForm.ShowModal;
  Result := SubForm.ModalResult;
  SubForm.Free;
end;

Also, with your main menu, don't close it out, just position it behind the popups.

 
The fastest way to find out why closing one form opens another is to debug the application. I'd bet that you have some code attached to the onclose or ondeactivate that automatically opens the other form.

I also recommend doing what Prattaratt suggested. In the IDE, select Project | Options and make sure the Forms tab is selected. Select all the forms (other than your main form) and remove it from the autocreate list and put them in the Available list.

Now, when your application starts, only the main form is automatically created. Every time you need another form, you'll need to dynamically create it. Also, you may want to select a modalresult for the buttons that close your modal forms - available as a property of the button in the object inspector. Modalresult can tell you which button the user used to close the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top