You need to keep a reference to the form in a higher scope than the procedure, since local variables are not preserved during multiple calls of a procedure. A suitable place could be a member in your TMAIN class. You could then check if the form exists and is visible, and hide it if that is the case.
Please make a new thread for questions unrelated to the initial one in the future. That is a forum rule here, with the purpose of keeping topics easy to
access with the search function and maintain a certain level of order.
i have created a new thread with it .