Puede haber varias maneras de hacer esto dependiendo del contexto exacto: ¿todos los formularios son del mismo tipo o tienen un ancestro común? Cuando se cierran los formularios, ¿se destruyen o sólo se esconden? ¿Son formularios MDIChild?
En fin, suponiendo que tú tienes control del momento en que se crean los formularios (es decir, que no se crean automáticamente al inicio) y que los destruyes al cerrarlos (poniendo Action := caFree en su evento OnClose), puedes valerte del método Notification del formulario principal para actualizar la cuenta:
Código Delphi
[-]
type
TMainForm = class(TForm)
private
FormCount: Integer;
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
end;
implementation
procedure TMainForm.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (AComponent is TForm) and (AComponent.Owner = Self) and (Operation = opRemove) then
begin
Dec(FormCount);
if (FormCount = 0) then
begin
ShowMessage('No more forms');
end;
end
end;
Al crear un formulario es necesario poner al principal como Owner y aumentar la cuenta de formularios:
Código Delphi
[-]
with TFormularioHijo.Create(Self) do
Show;
Inc(FormCount);
// Saludos