Ver Mensaje Individual
  #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
Reputación: 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