Ver Mensaje Individual
  #3  
Antiguo 21-08-2013
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Reputación: 13
steelha Va por buen camino
Muchas gracias ecfisa por responder, he copiado y modificado el código para adaptarlo pero aun así obtengo un error de :
Project GeneradorTicket.exe raised exception class EDatabaseError with message 'qryEstacioens:Field'ID' not found'. Process stopped. Use step or run to continue.

No entiendo el porque si el campo existe en la tabla :
ID
Descripcion
Activo
Online


Adaptacion del codigo
Código Delphi [-]
function TGenerador.GetActiveServiceStation: Integer;
var
  MaxRegs : Integer;
begin
  with dm.qryEstaciones do
  begin
    // Obtener el número total de estaciones de servicio activas
    Close;
    SQL.Text := 'SELECT COUNT(*) AS MAX_REG FROM tblRepresentante WHERE ACTIVO = ''S'' ';
    Open;
    if isEmpty then
      raise Exception.Create('No hay estaciones de servicio activas');
    MaxRegs :=  FieldByName('MAX_REG').AsInteger;

    // Seleccionar una estación de servicio activa al azar
    Close;
    SQL.Text := 'SELECT ID FROM tblRepresentante WHERE Activo = ''S'' ';
    Open;
    Randomize;
    Locate('ID', Random(MaxRegs), []);
    Result := FieldByName('ID').AsInteger;
    Close;
  end;
end;
Responder Con Cita