Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-09-2006
inferno inferno is offline
Miembro
 
Registrado: may 2005
Posts: 10
Poder: 0
inferno Va por buen camino
Cerrar Pantallas hijas en delphi 7.0

hola para todos los que me puedan ayudar tengo un programa que esta restringuido con acceso a él, le explico el problema un pequeño programa que necesita un login y una clave de acceso para entrar, pero no es el caso la cuestion es cuando un usuario desea cerra la sesión y el no ha cerrado todas las pantallas entonces cuando venga el nuevo usuario del sistema que accesa a él encontrará todas esas pàntallas abierta entonces yo quiciera saber como detectar cuales pantallas estan abierta para cerrarla así evitar que el nuevo usuario las encuentre abierta
Responder Con Cita
  #2  
Antiguo 28-09-2006
Sudamericano Sudamericano is offline
Miembro
 
Registrado: feb 2004
Posts: 41
Poder: 0
Sudamericano Va por buen camino
Cerrar ventanas hijas

Código:
procedure TFrmMain.ActCloseAllExecute(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to MDIChildCount - 1 do
    MDIChildren [i].Close;
end;
con esto busca ventanas abiertas y las cierra
Responder Con Cita
  #3  
Antiguo 28-09-2006
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Poder: 27
jachguate Va por buen camino
La propuesta de Sudamericano es válida en caso que tuvieras una aplicación MDI, cosa que no se ha aclarado.

Una solución mas genérica es basarse en el objeto global Screen, que guarda una lista a todas las formas creadas en su propiedad Forms:

Código Delphi [-]
begin
  for I := 0 to Screen.FormCount - 1 do
    if Screen.Forms[i].ClassName <> 'TFormularioLogin' then
      Screen.Forms[i].Close;

Hasta luego.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate
Responder Con Cita
  #4  
Antiguo 28-09-2006
inferno inferno is offline
Miembro
 
Registrado: may 2005
Posts: 10
Poder: 0
inferno Va por buen camino
Gracias por la ayuda

hola jachguate, utilize tu codigo por que tambien tengo tfrm en estilo normal y abierta con shomodal y necesitab algo general y funciona bien gracias....

otra cosa igualmente servirá este codigo para detectar las que estan abierta y reabrirla; (es decir si alguna tiene en sus campos edit,datos cuando valla abrirla no pierda la información)verda o hay algo mejor.Que me sirva
Responder Con Cita
  #5  
Antiguo 28-09-2006
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Poder: 27
jachguate Va por buen camino
Cita:
Empezado por inferno
otra cosa igualmente servirá este codigo para detectar las que estan abierta y reabrirla; (es decir si alguna tiene en sus campos edit,datos cuando valla abrirla no pierda la información)verda o hay algo mejor.Que me sirva
francamente, no entendí...

Saludos.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate
Responder Con Cita
  #6  
Antiguo 18-03-2008
zarzuela zarzuela is offline
Registrado
 
Registrado: nov 2006
Posts: 7
Poder: 0
zarzuela Va por buen camino
Mira que facil

En la forma principal, recuerda que hablamno de MDI padre puedes ponerte un boton generar que sirva para cerrar todos
y este código lo pones en el

if frmprincipal.MDIChildCount>=1 then
ActiveMDIChild.Close
else
Close;

end;
eso implica que si hay algun MDIChild activo lo cierra pero si es el formulario principal el activo entonces sales del sistema.
Puedes ponerlo o arregarlo a tu gusto.
Responder Con Cita
  #7  
Antiguo 01-05-2008
petitrad petitrad is offline
Registrado
 
Registrado: abr 2008
Posts: 7
Poder: 0
petitrad Va por buen camino
Como Cerrar Una Ventana Hija

Hola a todos es mi primera vez aqui en el foro y me gustaria saber como cerrar una ventana hija.

esta la creo con este codigo

Vventa := TVenta.Create(self);
Vventa.FormStyle := fsMDIChild;
Vventa.Left :=0;
Vventa.Top :=0;
Vventa.Width:=Screen.Width-15;
Vventa.Height:= Screen.Height-50;
Vventa.Parent := self;
Vventa.Name := 'Ventas';
Vventa.Show;

pero al ponerle que la cierra no se cierra no hace nada,
ya e tratado con mdicount, screenform y cosas asi pero todas me marcan error de memoria, tambien e tratado con destroy, close, free y pues nada, espero ustedes me ayuden.

ya que tengo el form principal y de ahi abro la pantalla de ventas y quiero que se pueda cerrar y volver a abrir luego, ya que realize un menu con un panel e imagenes, y si no creo el child seponen arriva del menu y si creo las childs no se suben arriva del menu, el unico problema que no puedo cerrarlas.

espero pronta respuesta gracias.
Responder Con Cita
  #8  
Antiguo 01-05-2008
Avatar de jcarteagaf
[jcarteagaf] jcarteagaf is offline
Miembro Premium
 
Registrado: abr 2006
Ubicación: La Paz, Bolivia
Posts: 651
Poder: 19
jcarteagaf Va por buen camino
Cuando quieras cerrar la ventana hijas usas lo siguiente:

Código Delphi [-]
VentanaHija.close; //asumiendo que lo estas llamando desde tu forma padre



y en el evento OnFormClose de la ventana hija colocas

Código Delphi [-]
procedure TfrmVentanaHija.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
end;

Saludos.
Responder Con Cita
  #9  
Antiguo 01-05-2008
Avatar de MaMu
MaMu MaMu is offline
Miembro
 
Registrado: abr 2006
Ubicación: Argentina
Posts: 863
Poder: 18
MaMu Va por buen camino
Código Delphi [-]
 
procedure TfrmVentanaHija.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
 frmVentanaHija:=nil;  //<-----no?  
 Action := caFree;
end;
__________________
Código Delphi [-]
 
try 
ProgramarMicro(80C52,'Intel',MnHex,True);
except
On Exception do
MicroChip.IsPresent(True);
end;
Responder Con Cita
  #10  
Antiguo 01-05-2008
petitrad petitrad is offline
Registrado
 
Registrado: abr 2008
Posts: 7
Poder: 0
petitrad Va por buen camino
No Puedo Cerrar Ventanas

ya he tratado de cerrarla de esta manera

procedure TfrmVentanaHija.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frmVentanaHija:=nil;
Action := caFree;
end;

me marca el sig error,

project QSoft.exe raised exception class EAccessViolation with message 'Access violation at address 000000000. Read of adress 000000000'. Process stopped. use step or run to continue.

si lo cierra, pero al intentarla abrir de nuevo me marca error que ya existe, pero si la abre, no se si esto es normal o deba hacer algo mas.

gracias
Responder Con Cita
  #11  
Antiguo 02-05-2008
Avatar de jcarteagaf
[jcarteagaf] jcarteagaf is offline
Miembro Premium
 
Registrado: abr 2006
Ubicación: La Paz, Bolivia
Posts: 651
Poder: 19
jcarteagaf Va por buen camino
Proba hacerlo de la siguiente forma

Código Delphi [-]
 procedure TfrmVentanaHija.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
  Action := caFree;
  frmVentanaHija:=nil;
 end;

pero tambien dependera de como crees la ventana si estas haciendo algo asi:

Código Delphi [-]
With TfrmVentanaHija.Create(application) do
  Show;

te marcara error de Access violation en el FormClose, debido a que el objeto frmVentanaHija no ha sido creado.

Normalmente yo creo y llamo a las formas hijas de la siguiente manera:

Código Delphi [-]
if frmVentanaHija = nil then
    frmVentanaHija := TfrmVentaHija.Create(application)
frmVentanaHija.Show;

En este caso, si la ventana hija ya ha sido creada, solamente la muestra.


Saludos.
Responder Con Cita
  #12  
Antiguo 02-05-2008
petitrad petitrad is offline
Registrado
 
Registrado: abr 2008
Posts: 7
Poder: 0
petitrad Va por buen camino
Aun marca error de memoria

aun me marca el mismo error, aqui esta el codigo que utilizo en las formas

Código Delphi [-]
//Principal 
unit Principal;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, LMDControl, LMDBaseControl, LMDBaseGraphicButton,
  LMDCustom3DButton, LMD3DEffectButton, ExtCtrls, StdCtrls,
  LMDCustomControl, LMDCustomPanel, LMDCustomBevelPanel, LMDSimplePanel,
  LMDCustomShapeButton, LMDShapeButton, LMDCustomParentPanel, LMDBackPanel;
type
  TMain = class(TForm)
    LogoQS: TImage;
    Panel1: TPanel;
    LetrasLP: TImage;
    NUsuario: TLabel;
    Fecha: TLabel;
    Hora: TLabel;
    Panel2: TPanel;
    LMDSimplePanel8: TLMDSimplePanel;
    BVentas: TLMDShapeButton;
    LMDSimplePanel9: TLMDSimplePanel;
    BCompras: TLMDShapeButton;
    LMDSimplePanel10: TLMDSimplePanel;
    BCuentasCobrar: TLMDShapeButton;
    LMDSimplePanel11: TLMDSimplePanel;
    BCuentasPagar: TLMDShapeButton;
    LMDSimplePanel12: TLMDSimplePanel;
    BReportes: TLMDShapeButton;
    LMDSimplePanel14: TLMDSimplePanel;
    BInventario: TLMDShapeButton;
    LMDSimplePanel13: TLMDSimplePanel;
    BUtilidades: TLMDShapeButton;
    LMDSimplePanel15: TLMDSimplePanel;
    BPalm: TLMDShapeButton;
    LMDSimplePanel16: TLMDSimplePanel;
    BSalir: TLMDShapeButton;
    procedure BSalirClick(Sender: TObject);
    procedure FormClick(Sender: TObject);
    procedure LMDSimplePanel8MouseEnter(Sender: TObject);
    procedure LMDSimplePanel9MouseEnter(Sender: TObject);
    procedure LMDSimplePanel10MouseEnter(Sender: TObject);
    procedure LMDSimplePanel11MouseEnter(Sender: TObject);
    procedure LMDSimplePanel12MouseEnter(Sender: TObject);
    procedure LMDSimplePanel13MouseEnter(Sender: TObject);
    procedure LMDSimplePanel14MouseEnter(Sender: TObject);
    procedure LMDSimplePanel15MouseEnter(Sender: TObject);
    procedure LMDSimplePanel16MouseEnter(Sender: TObject);
    procedure LogoQSClick(Sender: TObject);
    procedure LetrasLPClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BVentasClick(Sender: TObject);
    procedure BComprasClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    procedure AbreCotizacion();
  end;
var
  Main: TMain;
implementation
uses Ventas, MenuV, MenuC, MenuCC, MenuCP, MenuI, MenuR, MenuU, Compras,
  Cotizaciones;
{$R *.dfm}
procedure TMain.BSalirClick(Sender: TObject);
var
        I: integer;
begin
//cierra todas las ventanas que esten abiertas
for I := 0 to Screen.FormCount - 1 do
       Screen.Forms[i].Close;
Close;
end;
procedure pantalla_completa();
var
  HTaskbar : HWND;
begin
  TRY     //Obtener el  handle del Taskbar de Windows
    HTaskBar:=FindWindow('Shell_TrayWnd',nil );
    EnableWindow(HTaskBar,False);  //Deshabilitar el Taskbar
    ShowWindow(HTaskbar,SW_HIDE);   //Esconder el Taskbat
  FINALLY
    With  Main  do begin
      BorderStyle :=bsNone;
    //  FormStyle :=fsStayOnTop;
      Left :=0;
      Top :=0;
      Height :=Screen.Height;
      Width :=Screen.Width;
    end;
  END //FINALLY    end;
end;
procedure restaurar_pantalla_completa();
var
  HTaskbar : HWND;
  OldVal : LongInt;
begin
    HTaskBar:=FindWindow('Shell_TrayWnd',nil );
    SystemParametersInfo (97, Word (False), @OldVal, 0); //solo en Win 95/98/ME
    EnableWindow(HTaskBar,True);
    ShowWindow(HTaskbar,SW_SHOW);
end;
procedure TMain.FormClick(Sender: TObject);
begin
        //Esconde todos los menus.
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel8MouseEnter(Sender: TObject);
begin
        //Muestra Menu Ventas
        MVentas.Show;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel9MouseEnter(Sender: TObject);
begin
        //Muestra Menu Compras
        MVentas.Hide;
        MCompras.Show;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel10MouseEnter(Sender: TObject);
begin
        //Muestra Menu  Cuentas Por Cobrar
        MCC.Show;
        MVentas.Hide;
        MCompras.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel11MouseEnter(Sender: TObject);
begin
        //Muestra Menu Cuentas Por Pagar
        MCP.Show;
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel12MouseEnter(Sender: TObject);
begin
        //Muestra Menu Reportes
        MReportes.Show;
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel13MouseEnter(Sender: TObject);
begin
        //Muestra Menu Utilidades
        MUtilidades.Show;
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel14MouseEnter(Sender: TObject);
begin
        //Muestra Menu Inventarios
        MInventario.Show;
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
end;
procedure TMain.LMDSimplePanel15MouseEnter(Sender: TObject);
begin
        //Esconde todos los menus
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LMDSimplePanel16MouseEnter(Sender: TObject);
begin
        //Esconde todos los menus
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LogoQSClick(Sender: TObject);
begin
        //Esconde todos los menus
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.LetrasLPClick(Sender: TObject);
begin
        //Esconde todos los menus
        MVentas.Hide;
        MCompras.Hide;
        MCC.Hide;
        MCP.Hide;
        MReportes.Hide;
        MUtilidades.Hide;
        MInventario.Hide;
end;
procedure TMain.FormCreate(Sender: TObject);
var
  stSystemTime : TSystemTime;
begin
  Windows.GetLocalTime( stSystemTime );
  Hora.Caption := DateTimeToStr( SystemTimeToDateTime( stSystemTime ) );
  pantalla_completa();
end;
procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  restaurar_pantalla_completa();
end;
procedure TMain.BVentasClick(Sender: TObject);
begin
        //Crea y abre la ventana de ventas en modo Hija.
        if venta = nil then
        begin
              venta := TVenta.Create(self);
              venta.FormStyle := fsMDIChild;
              venta.Left :=0;
              venta.Top :=0;
              venta.Width:=Screen.Width-15;
              venta.Height:= Screen.Height-50;
              venta.Parent     :=  self;
        end;
        venta.Show;
end;
procedure TMain.BComprasClick(Sender: TObject);
begin
//Pendientes todas las formas
        Compra.Show;
end;
procedure TMain.AbreCotizacion();
begin
        Cotizacion.Show;
end;

End.
 
 
 
// Ventana Hija.
 
 
unit Ventas;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, LMDControl, LMDBaseControl, LMDBaseGraphicButton,
  LMDCustom3DButton, LMD3DEffectButton, LMDCustomControl, LMDCustomPanel,
  LMDCustomBevelPanel, LMDSimplePanel, StdCtrls, LMDCustomShapeButton,
  LMDShapeButton, Grids;
type
  TVenta = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Bevel1: TBevel;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Bevel3: TBevel;
    Bevel4: TBevel;
    Image4: TImage;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    LabeledEdit5: TLabeledEdit;
    LabeledEdit6: TLabeledEdit;
    LabeledEdit7: TLabeledEdit;
    LMDShapeButton1: TLMDShapeButton;
    StringGrid1: TStringGrid;
    LabeledEdit8: TLabeledEdit;
    LMDShapeButton2: TLMDShapeButton;
    LabeledEdit9: TLabeledEdit;
    LabeledEdit10: TLabeledEdit;
    LabeledEdit11: TLabeledEdit;
    LMDShapeButton3: TLMDShapeButton;
    LMDShapeButton4: TLMDShapeButton;
    LabeledEdit12: TLabeledEdit;
    LMDShapeButton5: TLMDShapeButton;
    procedure LMDShapeButton4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Venta: TVenta;
implementation
uses Principal;
{$R *.dfm}

procedure TVenta.LMDShapeButton4Click(Sender: TObject);
begin
        Close;
end;
procedure TVenta.FormClose(Sender: TObject; var Action: TCloseAction);
begin   
        Action := caFree;
        Venta := nil;
end;
end.

aun asi no funciona cambiando el action a la parte de abajo.

espero que me puedan ayudar.

Última edición por roman fecha: 02-05-2008 a las 03:36:53. Razón: Añadir etiqueta [delphi]
Responder Con Cita
  #13  
Antiguo 02-05-2008
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
petitrad: Por favor utiliza la etiqueta [delphi] para publicar código. Por esta vez te la he puesto yo para que veas la diferencia. Entra a editar tu mensaje para que veas cómo se usa.

// Saludos
Responder Con Cita
  #14  
Antiguo 02-05-2008
Avatar de jcarteagaf
[jcarteagaf] jcarteagaf is offline
Miembro Premium
 
Registrado: abr 2006
Ubicación: La Paz, Bolivia
Posts: 651
Poder: 19
jcarteagaf Va por buen camino
Podrias colocar los mensajes exactos que te marca?

El mensaje de Access violation en que momento ocurre?

Eso servira para identificar mejor tu problema.
Responder Con Cita
  #15  
Antiguo 02-05-2008
petitrad petitrad is offline
Registrado
 
Registrado: abr 2008
Posts: 7
Poder: 0
petitrad Va por buen camino
Errores

Ok, gracias moderador.

Los errores son los siguientes

project QSoft.exe raised exception class EAccessViolation with message 'Access violation at address 000000000. Read of adress 000000000'. Process stopped. use step or run to continue.

este error me marca al intentar reabrir la ventana y en onclose del form hija donde pongo el action := cafree y el ventana := nil, pero me marca otro erro al salir del programa que es:

Exception EAccessViolation in module vcl60.bpl at 0003fd57
Access violation at adress 005dfd57 in module 'vcl60.bpl'. read of adress 00000254.

espero que me puedan ayudar.
Responder Con Cita
  #16  
Antiguo 03-05-2008
petitrad petitrad is offline
Registrado
 
Registrado: abr 2008
Posts: 7
Poder: 0
petitrad Va por buen camino
Cerrar pantallas hijas

ya encontre el error, el detalle esta aqui, que si le pongo:

Ventana.parent := self, lo hace como yo quiero pero me marca error al cerrarla, si no le pongo eso si lo hace y se cierra y se puede abrir de nuevo, pero como podria utilizar esta propiedad y cuando lo cierre quitarsela, intente ponerle en nil pero al parecer me manda a nil el principal tambien bueno espero me puedan ayudar ya que es un proyecto importante para la escuela.

hasta pronto.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Busco un consejo (muchas ventanas hijas y muchos menús) ixMike Varios 9 14-09-2006 11:23:34
Recorrido de ventanas hijas sur-se OOP 3 23-08-2004 11:43:10
La señora y sus hijas roman Humor 24 28-05-2004 19:46:20
Ventanas MDI Hijas LucianoRey OOP 4 25-02-2004 01:28:32
Problemas con formas Hijas (MDI Child) D.M Varios 1 10-09-2003 22:56:30


La franja horaria es GMT +2. Ahora son las 20:57:16.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi