Ver Mensaje Individual
  #1  
Antiguo 22-08-2015
cocute cocute is offline
Miembro
 
Registrado: nov 2008
Posts: 403
Reputación: 16
cocute Va por buen camino
¿Cómo guardar el estado de un Tswitch del modo más simple?

Pues eso quiero guardar el estado ischecked de un Tswitch, para que se guarde si quiero sonido en la aplicación o no.
No se si me he liado mucho pero esto es lo que intento y no me lo guarda.
Lo que hago es crear un fichero sonido.ini, y luego comprobar si existe ese fichero,
y si existe el fichero que no suene. Pero no me funciona.
En lo de permisos tengo marcado "write in external extorage", no se si necesito algo más.
O si hay algún modo mejor de hacerlo¿?

Por defecto el TSwitch está checked.

Esto pongo en el onshow del form
Código Delphi [-]
procedure TForm.FormShow(Sender: TObject);
begin
if FileExists( TPath.GetDocumentsPath + PathDelim + 'sonido.ini' ) then swtchchk1.IsChecked:=false;

if not FileExists(TPath.GetDocumentsPath + PathDelim + 'sonido.ini') then
       begin
  MP1.FileName := TPath.GetDocumentsPath + PathDelim + 'sonido.mp3';
  MP1.Play;
       end;
end;

y esto en el switch
Código Delphi [-]
procedure TForm.swtchchk1Switch(Sender: TObject);
begin
if swtchchk1.IsChecked=true then
begin
   if FileExists( TPath.GetDocumentsPath + PathDelim + 'sonido.ini' )
   then
       begin
        TFile.Delete( TPath.GetDocumentsPath + PathDelim + 'sonido.ini' );
        mp1.play;
    end;
end;
if swtchchk1.IsChecked=false then
begin
TFile.Create( TPath.GetDocumentsPath + PathDelim + 'sonido.ini' );
mp1.Stop;
end;

end;

Última edición por cocute fecha: 22-08-2015 a las 10:15:55.
Responder Con Cita