Ver Mensaje Individual
  #3  
Antiguo 27-04-2007
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Reputación: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Probablemente con lo que aporta el compañero Neftalí baste, pero, en fin, ya lo había hecho...

Código Delphi [-]
unit UAbecedario;

interface

type
  TAbecedario = class(TObject)
  private
    FLetras: string;
    FPosicion: byte;
  public
    constructor Create();
    function Actual(): char;
    function Anterior(): char;
    function Siguiente(): char;
  end;

implementation

resourcestring
  rsLetras = 'abcdefghijklmnñopqrstuvwxyz';

{ TAbecedario }

constructor TAbecedario.Create();
begin
  inherited Create();
  FPosicion := 1;
  FLetras := rsLetras;
end;

function TAbecedario.Actual(): char;
begin
  result := FLetras[FPosicion];
end;

function TAbecedario.Anterior(): char;
begin
  Dec(FPosicion);
  if (FPosicion = 0) then
    FPosicion := Length(rsLetras);
  result := FLetras[FPosicion];
end;

function TAbecedario.Siguiente(): char;
begin
  Inc(FPosicion);
  if (FPosicion > Length(rsLetras)) then
    FPosicion := 1;
  result := FLetras[FPosicion];
end;

end.

Supongo que puede mejorarse... o en todo caso hacerse de otro modo más elegante. Aporto, en todo caso, un ejemplo de uso de la clase que he copiado arriba.
Archivos Adjuntos
Tipo de Archivo: zip ejemplo.zip (2,4 KB, 14 visitas)
__________________
David Esperalta
www.decsoftutils.com

Última edición por dec fecha: 27-04-2007 a las 18:52:52.
Responder Con Cita