El código es el siguiente:
Código Delphi
[-]
......
.....
function TForm1.GetValIni(secc, val: string): string;
begin
INI := TINIFILE.Create(Config);
Result := INI.ReadString(secc, val, '');
INI.Free;
end;
function TForm1.ObtenerDatosConnDB: boolean;
begin
if CheckValIni('BD', 'Inst') and CheckValIni('BD', 'Usuario') and
CheckValIni('BD', 'Usuario') then
begin
MSSQLConnection1.HostName := GetValIni('BD', 'Inst');
MSSQLConnection1.UserName := GetValIni('BD', 'Usuario');
MSSQLConnection1.Password := descifrar(GetValIni('BD', 'Pass'));
Result := True;
exit;
end;
Result := False;
end;
function TForm1.ObtenerBDEjActual: string;
begin
if ObtenerDatosConnDB then
begin
MSSQLConnection1.DatabaseName := 'COMU0001';
MSSQLConnection1.Connected := True;
if MSSQLConnection1.Connected then
begin
SQLQuery1.SQL.Text := 'SELECT [CONEXION] ' +
'FROM ejercici ' +
'WHERE [ANY] = '
+ '''' + FormatDateTime('yyyy', Now) + ''';';
SQLQuery1.Open;
Result := SQLQuery1.FieldByName('CONEXION').AsString;
SQLQuery1.Close;
exit;
end;
MSSQLConnection1.Connected := False;
end;
end;
...
...
procedure TForm1.Button3Click(Sender: TObject);
var
prueba: string;
begin
prueba := ObtenerBDEjActual;
ShowMessage(prueba);
end;
El problema es al pulsar por segunda vez el botón que me genera una excepción de la clase 'External: SIGSEGV', la primera vez obtengo sin problemas los datos de la query. ¿Cómo puedo solucionarlo?. Gracias de antemano.