Ver Mensaje Individual
  #4  
Antiguo 14-05-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Se me ha ocurrido algo así después de un rato dándole vueltas:

Código Delphi [-]
function HasShowingFormsInScreen
 (alsoMainForm:boolean=false):boolean;
var
  i: integer;
begin
  Result := false;
  for i:=0 to Screen.FormCount-1 do
  begin
    if Result then
      Exit;
    if Screen.Forms[i].Showing then
    begin
      with Screen, Application do
      begin
        if (Forms[i] = MainForm) then
          Result := alsoMainForm
        else
        begin
          Result := true;
          Exit;
        end;
      end;
    end;
  end;
end;

Por cierto, gracias a Marcos y a freelance, quienes me han ayudado. A Marcos porque no recordaba la variable "FormCount" del objeto "Screen", y, a freelance, porque me picó a comprobar que la función de más arriba parece funcionar tanto en aplicaciones MDI (Multiple Document Interface) como SDI (Single Document Interface).

Por cierto, una posible forma de hacer uso de la función anterior, siguiendo lo que dice freelance de utilizar el evento "OnCloseQuery" del formulario principal de la aplicación:

Código Delphi [-]
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  { Sin tener en cuenta el formulario principal
  }
  if HasShowingFormsInScreen then
  begin
    ShowMessage('¡Cierra las ventanas que hace frío! ;-)');
    CanClose := false;
  end;

  { Teniendo en cuenta el formulario principal

  if HasShowingFormsInScreen(true) then
  begin
    ShowMessage('¡Cierra las ventanas que hace frío! ;-)');
    CanClose := false;
  end;
  }
end;
__________________
David Esperalta
www.decsoftutils.com

Última edición por dec fecha: 14-05-2006 a las 19:42:57.
Responder Con Cita