PDA

Ver la Versión Completa : error en ejecuciones constante en aplicacion...


novato_erick
06-02-2013, 17:11:53
Hola chicos como estan?

Quiero hacer una consulta tengo un pequeño problema ya que stoy realizando una aplicacion el cual necesito que me mande tres sonidos diferente a la hora de confirmar por ejemplo una marcación.


Ya logre eso sin embargo haciendo prueba note que al ser la segunda o tercera marcación seguida me cierra el programa mandandome el tipico error de windows "aplicacion.exe ah detectado un problema y debe cerrarse" cuando un programa es interrumpido.

pueda ser liberacion de memoria inadecuadamente bueno la verdad no se pero me gustaria que me pudieran ayudar...

envio este codigo para que vean que hago...


function cargarFicheroMemoria (const fichero : TFileName): string;
begin
with TFileStream.Create(fichero,
fmOpenRead or fmShareDenyWrite) do
begin
try
SetLength(Result, Size);
Read(Pointer(Result)^, Size);
except
Result := '';
Free;
raise;
end;
Free;
end;
end;

procedure sonidoconfirma;
var
ficheroSonido : string;

begin
//cargar fichero en memoria
case Sonido of

1: ficheroSonido := cargarFicheroMemoria ('C:\EDD TXT TECNOLOGIA MARCACION\voces\confirmacion.wav');
2: ficheroSonido := cargarFicheroMemoria ('C:\EDD TXT TECNOLOGIA MARCACION\voces\confirmacionHombre.wav');
3: ficheroSonido := cargarFicheroMemoria ('C:\EDD TXT TECNOLOGIA MARCACION\voces\noencontrado.wav');
//reproducir fichero
end;

sndPlaySound(Pointer(ficheroSonido), SND_MEMORY
Or SND_NODEFAULT Or SND_ASYNC);
ficheroSonido := '';
sonido:= 0;
end;

procedure TfrmAsistencia.AgregaAsistencia;
begin
dmStoreProcedure.spConsultaCedula.Params.ParamByName('CEDULA').AsString :=
edtCedula.Text;
dmStoreProcedure.spConsultaCedula.ExecProc;
Id_emplAsis := dmStoreProcedure.spConsultaCedula.Params.ParamByName('ID')
.AsInteger;
if Id_emplAsis >= 1 then
begin
with dmConectar.qMarcaciones do
begin
ParamByName('pID_EMPLEADOS').AsInteger := Id_emplAsis;
execsql;
with dmConectar.qConsultaEmpl do
begin
close;
ParamByName('pIDEMPL').AsInteger := Id_emplAsis;
execsql;
end;
dmConectar.qConsultaEmpl.Open;
lblCedula.Caption := dmConectar.qConsultaEmplCEDULA_EMPL.AsString;
lblNombre.Caption := dmConectar.qConsultaEmplNOMBRE_EMPL.AsString;
IFoto.Picture.LoadFromFile(dmConectar.qConsultaEmplIMAGEN_EMPL.AsString);
begin
if dmconectar.qConsultaEmplID_GENERO.asinteger = 2 then
begin
sonido:= 2;
sonidoconfirma;
end
else
begin
sonido:=1;
sonidoconfirma;
end;
end;
end;
end
else
begin
sonido:= 3;
sonidoconfirma;
end;
end


//Procedimiento que utilizo con timer para que me cambie la foto despues de haber mostrado la imagen del colaborador encontrado
procedure TfrmAsistencia.tcorrectoTimer(Sender: TObject);
begin
lblCedula.Visible := false;
begin
IFoto.Picture.LoadFromFile('c:\EDD TXT TECNOLOGIA MARCACION\fotos\picture03.png');
end;
lblNombre.Visible := false;
edtCedula.Text := '';
edtCedula.setFocus;
tcorrecto.Enabled:= false;

end;
//Muestra hola al usuario
procedure TfrmAsistencia.Timer1Timer(Sender: TObject);
begin
LblHora.Caption := FormatDateTime('hh:mm:ss ampm',Now);
end;



saludos

novato_erick

ecfisa
07-02-2013, 03:55:26
Hola novato_erick.

Según entiendo deseas almacenar el contenido de un archivo .wav en un string y luego reproducirlo desde allí con la función sndPlaySound. Desconozco si hay manera de hacerlo funcionar de ese modo, pero lo dudo.

De este modo no te ofrecerá ningún problema:

procedure sonidoconfirma(Sonido: Integer);
var
fichero: string;
begin
case Sonido of
1: fichero:= 'C:\Windows\Media\chimes.wav';
2: fichero:= 'C:\Windows\Media\chord.wav';
3: fichero:= 'C:\Windows\Media\ding.wav';
//...
else
raise Exception.Create('Elección fuera de rango');
end;
with TMemoryStream.Create do
try
LoadFromFile(fichero);
sndPlaySound(Memory, SND_MEMORY + SND_SYNC)
finally
Free
end
end;


Aunque no veo la nececidad de hacerlo de ese modo, sería mucho más simple:

procedure sonidoconfirma(Sonido: Integer);
var
fichero: string;
begin
case Sonido of
1: fichero:= 'C:\Windows\Media\chimes.wav';
2: fichero:= 'C:\Windows\Media\chord.wav';
3: fichero:= 'C:\Windows\Media\ding.wav';
//...
else
raise Exception.Create('Elección fuera de rango');
end;
sndPlaySound(PChar(fichero), SND_NODEFAULT + SND_SYNC);
end;


Saludos. :)