Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Desarrollo en Delphi para Android
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy


Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-08-2015
cocute cocute is offline
Miembro
 
Registrado: nov 2008
Posts: 403
Poder: 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
  #2  
Antiguo 24-08-2015
cocute cocute is offline
Miembro
 
Registrado: nov 2008
Posts: 403
Poder: 16
cocute Va por buen camino
nada que no hay manera de que me guarde y recupere configuraciones, ni usando ficheros ini tampoco
Que es lo que hago mal?
en este caso intento guardar en un ini el valor de un trackbar "tr1", pero no hay manera tampoco.

Código Delphi [-]
procedure TForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
 var
   Ini: TIniFile;
 begin
   Ini := TIniFile.Create(TPath.GetDocumentsPath + PathDelim + 'SAVE.INI' ) ;
   try
     Ini.WriteFloat('tr1', 'Value', tr1.Value);
   finally
     Ini.Free;
   end;

end;

Código Delphi [-]
procedure TForm.FormCreate(Sender: TObject);

 var
   Ini: TIniFile;
 begin
if FileExists( TPath.GetDocumentsPath + PathDelim + 'SAVE.INI' ) then
 begin

   Ini := TIniFile.Create(TPath.GetDocumentsPath + PathDelim + 'SAVE.INI' ) ;
   try
     Ini.readfloat('tr1', 'Value', tr1.Value);
   finally
     Ini.Free;
   end;

 end;
Responder Con Cita
  #3  
Antiguo 24-08-2015
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Poder: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

¿Estás seguro de que "GetDocumentsPath" es la ruta adecuada para usar en aplicaciones Android? Primero el archivo debe existir, después has de tener permisos de lectura y escritura sobre el mismo. Yo creo que por ahí van los tiros, puesto que el código que muestras no contiene nada raro y debería funcionar si lo anterior se cumpliese. Infórmate sobre qué rutas has de usar para guardar archivos de configuración para tu aplicación. Y si ya estás usando la correcta... entonces me temo que no se me ocurre otra cosa sino tratar de depurar lo mejor posible lo que haces ahora.
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita
  #4  
Antiguo 24-08-2015
cocute cocute is offline
Miembro
 
Registrado: nov 2008
Posts: 403
Poder: 16
cocute Va por buen camino
pues no se no hay manera,
igual si meto en el deployment el fichero ini me funcione?
pero que carpeta le pongo en el valor Remote Path que me deje modificar el archivo?
Responder Con Cita
  #5  
Antiguo 24-08-2015
cocute cocute is offline
Miembro
 
Registrado: nov 2008
Posts: 403
Poder: 16
cocute Va por buen camino
Al final creo que lo he solucionado, si usar inis, guardando datos en un memo invisible
he guardado el valor del volumen del sonido de un trackbar
y si quieres sonido o no de un switch

Código Delphi [-]
procedure TForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
 begin
mmo1.Lines.Strings[1]:=FloatToStr(tr1.Value);
if swtchchk1.IsChecked=True then  mmo1.Lines.Strings[0]:='1';
if swtchchk1.IsChecked=false then  mmo1.Lines.Strings[0]:='0';

mmo1.Lines.savetoFile(TPath.Combine(TPath.GetDocumentsPath, 'SAVE.INI' )) ;


end;

procedure TForm.FormCreate(Sender: TObject);

 begin
if FileExists( TPath.Combine(TPath.GetDocumentsPath, 'SAVE.INI')) then
 begin
mmo1.Lines.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, 'SAVE.INI' )) ;
tr1.Value:=StrTofloat(mmo1.Lines.Strings[1]);
if mmo1.Lines.Strings[0]='1' then swtchchk1.IsChecked:=True;
if mmo1.Lines.Strings[0]='0' then swtchchk1.IsChecked:=false;

end;
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
Como Invertir Una Lista Enlazada Simple sant0s OOP 10 14-12-2011 20:55:24
Hola, ¿como han estado? D-MO La Taberna 9 12-09-2011 11:26:26
como insertar comilla simple en mysql server granodetoro MySQL 1 03-05-2011 03:12:41
Modo diseño y modo ejecución buildero_d OOP 3 11-09-2005 06:45:00
Como crear un navegador web simple CeNtInElA Internet 4 25-02-2005 14:31:06


La franja horaria es GMT +2. Ahora son las 22:46:40.


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