Hola Luis.Lapuente.
Si alguno de los TEdit (
Edit1 o
subtotal) no tienen contenido, la función
StrToFloat lanzará una excepción ya que la cadena vacía no es suceptible de ser convertida a número de punto flotante.
Tres opciones que evitan la situación:
A)
Código Delphi
[-]
var
A,B: Double;
begin
try
A:= StrToFloat(Edit1.Text);
except
Edit1.SetFocus;
raise Exception.Create('Edit1 no tiene un número decimal válido');
end;
try
A:= StrToFloat(subtotal.Text);
except
subtotal.SetFocus;
raise Exception.Create('subtotal no tiene un número decimal válido');
end;
B)
Código Delphi
[-]
var
A,B: Double;
begin
if not TryStrToFloat(Edit1.Text, A) then
begin
Edit1.SetFocus;
raise Exception.Create('Edit1 no tiene un número decimal válido');
end;
if not TryStrToFloat(subtotal.Text, B) then
begin
subtotal.SetFocus;
raise Exception.Create('subtotal no tiene un número decimal válido');
end;
C)
Código Delphi
[-]
var
A,B: Double;
begin
A:= StrToFloatDef(Edit1.Text, 0); B:= StrToFloatDef(subtotal.Text, 0);
Saludos