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
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;
Close;
SQL.Text := 'SELECT ID FROM tblRepresentante WHERE Activo = ''S'' ';
Open;
Randomize;
Locate('ID', Random(MaxRegs), []);
Result := FieldByName('ID').AsInteger;
Close;
end;
end;