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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.