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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShowModal crash but Show OK - help!

Status
Not open for further replies.

DaveWin31

Programmer
Dec 6, 2008
7
US
Hi All,

Weird thing has started happening to a program I have been developing in my spare time for months.

I have a search dialog that I "ShowModal" and it has started throwing an Exception on Close. If I change the call to "Show" it close OK with no exception.

I have stepped through it and it does not take me to where the exception is. I used the CallStack window but that just shows the original call. I have removed stuff and disabled all manner of stuff but still it persists with ShowModal. The actual Search process all works fine, the problem arises just after the "Close" statement in the Search dialog.

Any thoughts to help me clear this up?

Thanks
 
Perhaps you are Freeing the form twice. When you open the form via a ShowModal, I assume you are doing so like:

Code:
NewForm := TForm2.Create(...);
try
   NewForm.ShowModal
   if NewForm.ModalResult = mrOK then
      //do stuff
finally
   NewForm.Free;//object freed here.
end;

Also, if you have OnClose defined like so in the form you are opening

Code:
TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   Action := caFree;//Sets to free the object.
end;

In this case, your code would attempt to free the form twice, the second attempt would generate an access violation. This wouldn't happen if you "show" the form because you wouldn't free the form depending on the form's modal result.
 
@majlumbo:
Thanks, not quite the issue but it did make me look in the Show and OnClose events. It is something to do with the SQLite database that was being reset in the OnClose. Have not quite tracked it down, but now I am on the right path. Thanks a bunch that drove me nuts for several hours.

The key you gave me was the Show does not free the form. From there it was an easy track to the SQLite area. I will have to see what I have recently changed there.

Much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top