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 25-01-2018
gdlrinfo gdlrinfo is offline
Miembro
 
Registrado: may 2007
Posts: 131
Poder: 17
gdlrinfo Va por buen camino
Memorizar opciones con CheckBox

Estimados quisiera saber como hacer para mantener una elección de un CheckBox en una aplicación.-
Por ejemplo .

Quiero dejar 2 checkbox tildados y que cuando alguien cierre la aplicación sigan marcados o desmarcados (depende lo que el usuario ponga), es decir que se memorice si fue marcado o no !

Desde ya muchas gracias .--
Responder Con Cita
  #2  
Antiguo 25-01-2018
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Poder: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Una opción rápida es generar un archivo INI con esos datos.
Al abrir la aplicación lo lees.
Al cerrar lo guardas.

Código Delphi [-]
function LeeDatoIni(FicheroINI: string; const Section, Ident: string; Default: string = ''): string; overload;
begin
  with TIniFile.Create(FicheroINI) do
  begin
     try
        Result := ReadString(Section, Ident, Default);
     finally
        Free;
     end;
  end;
end;

function LeeDatoIni(FicheroINI: string; const Section, Ident: string; Default: integer = 0): integer; overload;
begin
  with TIniFile.Create(FicheroINI) do
  begin
     try
        Result := ReadInteger(Section, Ident, Default);
     finally
        Free;
     end;
  end;
end;

function LeeDatoIni(FicheroINI: string; const Section, Ident: string; Default: TDateTime = 0): TDateTime; overload;
begin
  if (Default = 0) then
     Default := Now;
  with TIniFile.Create(FicheroINI) do
  begin
     try
        Result := ReadDateTime(Section, Ident, Default);
     finally
        Free;
     end;
  end;
end;

procedure EscribeDatoIni(FicheroINI: string; const Section, Ident, Dato: string); overload;
begin
  with TIniFile.Create(FicheroINI) do
  begin
     try
        WriteString(Section, Ident, Dato);
     finally
        Free;
     end;
  end;
end;

procedure EscribeDatoIni(FicheroINI: string; const Section, Ident: string; Dato: integer); overload;
begin
  with TIniFile.Create(FicheroINI) do
  begin
     try
        WriteInteger(Section, Ident, Dato);
     finally
        Free;
     end;
  end;
end;

procedure EscribeDatoIni(FicheroINI: string; const Section, Ident: string; Dato: TDateTime); overload;
begin
  with TIniFile.Create(FicheroINI) do
  begin
     try
        WriteDateTime(Section, Ident, Dato);
     finally
        Free;
     end;
  end;
end;


var
  FicheroINI : string;
begin
   // El ini es el nombre de la aplicacio + .INI
   FicheroINI := ChangeFileExt(ExtractFileName(Application.ExeName), '.INI');

   // Leo el estado de los checkbox
   Checkox1.Checked := (LeeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox1', 0) = 1);
   Checkox2.Checked := (LeeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox2', 0) = 1);
   ...

   // Guardo el estado de los checkbox
   if Checkox1.Checked then
      EscribeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox1', 1)
   else
      EscribeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox1', 0);

   if Checkox2.Checked then
      EscribeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox2', 1)
   else
      EscribeDatoIni(FicheroINI, 'EstadoCheckBox', 'CheckBox2', 0);

end;
Responder Con Cita
  #3  
Antiguo 25-01-2018
gdlrinfo gdlrinfo is offline
Miembro
 
Registrado: may 2007
Posts: 131
Poder: 17
gdlrinfo Va por buen camino
GRaciaS

Muchas Gracias Voy a probarlo !
Responder Con Cita
  #4  
Antiguo 26-01-2018
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.267
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Si tu aplicación trabaja con Bases de Datos, otra opción es guardar esa configuración en una tabla de la Base de Datos (una tabla de CONFIGURACION).
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
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
Checkbox en opciones del Menu mRoman OOP 2 25-04-2016 07:01:36
No memorizar cuando se pulsa ATRAS KeyMan PHP 2 28-03-2008 20:10:18
uso CheckBox con 3 opciones arespremium OOP 5 26-08-2007 05:26:13
Opciones en Componente diegofhernando OOP 1 29-06-2004 15:39:09
Opciones de Parent pepelu1975 OOP 7 26-05-2004 18:35:36


La franja horaria es GMT +2. Ahora son las 08:43:25.


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