cocute
22-08-2015, 11:08:37
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
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
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;
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
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
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;