I keep running into this strange problem. It almost seems to be random but I run my application and open a form, do some work with it and close it. The next time I go to open another isntance of that form I get an error message about the form already existing. This is very odd and I haven't been able to constantly reproduce the error.
If it helps I'm using Delphi 6 still. Is there some known reason why this is happening or what I can do to prevent it?
Are you sure the form is not being hidden when it is closed?
That is the default for MDI forms, but I have seen other people do the same (to speed up re-showing the form).
Edit (thanks Cosmin Prund for the comment!):
Hook the OnClose
event of your form, and look what the value of the CloseAction
parameter is. If it is caHide
, then the form is hidden.
A temporary hack might be to assign caFree
to the CloseAction
, but a better solution is to watch the stack in your OnClose
event handler to see how you ended up there, and what is causing the CloseAction
to be caHide
in the first place.
Note: in these situations you often want to see what the VCL does. So it is wise to enable the debug DCUs
for your project; see this blog article how to do that (search for debug DCUs
in the link).
--jeroen