Ver Mensaje Individual
  #1  
Antiguo 22-05-2015
Avatar de bulc
bulc bulc is offline
Miembro
 
Registrado: jun 2010
Posts: 416
Reputación: 15
bulc Va por buen camino
Error en el recuento de un Array

Llevo toda la tarde y no consigo ver dónde está el error. El array de Label's me da un indice sin nombre y con un elemento de más.
Un Label aparece desplazado en medio de la pantalla. Lo he comparado con otro que funciona bien y nada. Me rindo... por hoy.
A ver si vosotros veis el gazapo... Echádle un vistazo, por favor.
Código Delphi [-]
procedure TForm1.Button3Click(Sender: TObject);  // Shuffle Shape's & Label's
var
  i, a, b: Integer;   AuxLbl, AuxShp: TPoint;
begin
//ShowMessage( IntToStr( Length(Label_A)) +'  ' + IntToStr( Length(Label_A)) +'  '+ IntToStr( Length(Label_A)) );   // Muestra 25!!!
Randomize;
  for i:= Low(Label_A) to High(Label_A) - 1  do
  begin
    a:= Random(High(Shape_A)+ 1);
    b:= Random(High(Shape_A)+ 1);

    AuxShp:= Point(Shape_A[a].Left, Shape_A[a].Top);
    AuxLbl:= Point(Label_A[a].Left, Label_A[a].Top);

    Shape_A[a].Left:= Shape_A[b].Left;
    Shape_A[a].Top := Shape_A[b].Top;

    Label_A[a].Left:= Label_A[b].Left;
    Label_A[a].Top:= Label_A[b].Top;

    Shape_A[b].Left:= AuxShp.X;
    Shape_A[b].Top := AuxShp.Y;

    Label_A[b].Left:= AuxLbl.X;
    Label_A[b].Top := AuxLbl.Y;

end;

Memo2.Clear;
for I :=0 to High(Shape_A) do
begin
   Memo2.Lines.Add( 'Shape:' +InttoStr(I) + ' ' + Shape_A[i].Name + '  left  ' +   InttoStr( Shape_A[i].Left)
      +' Top ' + InttoStr( Shape_A[i].Top)  );
end;
for I := 0 to High(Label_A) do
Memo1.Clear;
for I := 0 to High(Label_A) do
  begin
  // El Indice, érroneamente, va de 0 ->24 = 25 Labels y aparece el índice 22 sin nombre, con el Top erróneo.
    Memo1.Lines.Add( 'Index: ' +IntToStr(I)  + ' ' +Label_A[i].Caption +'  Left   '+
      IntToStr(  Label_A[i].Left )+' Length '+ IntToStr(Length(Label_A))+'  T '+  IntToStr(  Label_A[i].Top )  ) ;
  end;
end;
////////////////////////////////////////////////////////
Muchas gracias por el esfuerzo. Si hace falta más código, lo envío.
Saludos.
Bulc
Responder Con Cita