Dynamically Created Components(Again! )

OK...you great people have almost got me there!  My application dynamically creates forms and buttons as they are need!  However..as I suspected, deallocation of these compents is a problem.
I have buttons which are dynamically created as need, then, on the click of each newly created button a form is dynamically created as well. Here is the problem...I need to write a simple decision block which, on the click of a new button, will close any forms that may be open( Except Form1) and open the new form.  The decision code would be no problem If I could figure out how to access the open form!  I tried setting Form1.FormStyle to fsMDIParent, then setting all the new forms to fsMDIChild, the I wrote the block

  var count : Integer;
  begin
  With Form1 Do
    For count := MDIChildCount-1 downto
                 0 do
      MDIChildren[count].close;
  end;

But This did very strange things...in fact...just setting the forms to fsMDIChild made strange things happen.  
So when the Help files fail, its time it visit EE!

So to sum it up...Is there anyway...I'm sure there is..I'm just not bright enough to figure it out =)...to clean up the mess I'm making by all this dynamic allocation?  

PS : Sorry about the low points, I simply don't have any to give. I am new to delphi..and have too many questions on this project!

Thanks in advance!
mcdonluAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
you can use the screen.forms call.

example:

procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
form3.show;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i : integer;
begin
for i := 0 to screen.FormCount - 1  do begin
if not(screen.Forms[i].caption = 'Form1') then
screen.forms[i].close;
end;
end;

does that help
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.