views:

87

answers:

2

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?

A: 

You haven't provided the code, but it seems you are giving both form instances the same component name, and the owner of both forms is the same (probably Application object).

You cannot have components with the same name owned by another component. You should either give different names to each form instance, or just don't give any value to Name property, and let RTL choose a unique component name for your newly created instances.

If this is not the case with you, please provide the code by which you create your form instances, so that we can check what else might be wrong with the form.

vcldeveloper
+3  A: 

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

Jeroen Pluimers
+1. Testing on Delphi 2010, caHide seems to be the default OnClose Action for normal forms as well.
Cosmin Prund
+1 just popped on to give the same answer as you provided (you were much more eloquent than I would have been!)
MarkRobinson