Ver Mensaje Individual
  #4  
Antiguo 21-03-2009
Avatar de Delphius
[Delphius] Delphius is offline
Miembro Premium
 
Registrado: jul 2004
Ubicación: Salta, Argentina
Posts: 5.582
Reputación: 27
Delphius Va camino a la fama
Hola Iron,

Desconozco si existe alguna función ya hecha en Delphi que haga lo que pides. Pero no creo que resulte tan complicado hacerlo.

Por ejemplo, valiendome del tipo TIntegerDynArray que es un array dinámico de tipo entero es posible hacer dicha función.

Código Delphi [-]
function TForm1.Choose(Position: integer; ArrayNumber: TIntegerDynArray): integer;
begin
  if (Position <= High(ArrayNumber)) AND (Position >= 0)
     then result := ArrayNumber[Position]
     else raise exception.Create('Position out of range');
end;

Y un modo de usarla sería algo como éste:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var arreglo: TIntegerDynArray;
    i: integer;
begin
  SetLength(arreglo,6);
  for i := Low(arreglo) to High(arreglo) do
     arreglo[i] := random(123);

  ShowMessage(IntToStr(Choose(2,arreglo)));

  SetLength(arreglo,0);
  arreglo := nil;
end;

Se puede mejorar evidentemente. Pero al menos es una aproximación.

Saludos,
__________________
Delphius
[Guia de estilo][Buscar]

Última edición por Delphius fecha: 21-03-2009 a las 22:46:25. Razón: etiquetas delphi!
Responder Con Cita