procedure TForm1.CloseClick(Sender: TObject);
var i:integer;
begin
if form1.MDIChildCount>0 then
begin
for i:=0 to form1.MDIChildCount-1do
begin
if form1.ActiveMDIChild=form1.MDIChildren then
form1.MDIChildren.Close;
end;
end
else
application.Terminate;
end;