Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Acceder a un Array de StaticText (https://www.clubdelphi.com/foros/showthread.php?t=95578)

bulc 19-02-2022 21:27:10

Acceder a un Array de StaticText
 
No consigo acceder a un Array de StaticText para cruzar los rótulos de manera aleatoria para descolorlos respecto a su posición Inicial. El STx_Array se recoge en el evento OnCreate. Uso pares formados
por los cuatro primeros elementos y los otros cuatro de un String con ocho dígitos.
Gracias por vuestras sugerencias.
Código Delphi [-]
procedure TForm1.BtnCruzaSTexClick(Sender: TObject);
Var    // Funciona bien. Saca 8 números al azar.
   I, IAzar: Integer;  S, R : String;  // La var Str R es prescindible.
   Aux : TPoint;
begin
Aux.X := 0 ;
Aux.Y := 0 ;
 Randomize;  // In Initialization
 S := '';  // Importante
 REPEAT
   IAzar := Random(8) + 1;
   R := IntToStr(IAzar );
   if (Pos( R,  S) = 0)  then
      Insert( R,  S,  Length(S) + 1);
 //ShowMessage( IntToStr(Cont)+' '+ R ) ;
 UNTIL Length(S) = 8 ;
 Edit1.Text := S ;
//////////////////////////////////////////////////////////////////////////
for I := 1 to 4 do
  begin
  // ShowMessage( S[i]+ '  ' + S[I+4]  );
  Aux.X :=STx_A[i].Left;    Aux.Y :=STx_A[i].Top;
  STx_A[i].Left :=  STx_A[I+4].Left   ;
  STx_A[i].Top :=  STx_A[I+4].Top   ;
  STx_A[I+4].Left := Aux.X ;
  STx_A[I+4].Top := Aux.Y ;
  end;
end;

bulc 20-02-2022 21:37:41

Resuelto
 
Apunto la solución. He creado un Array de TPoint y otro de TStaticText que se cargan en el evento onCreateForm
Código Delphi [-]
procedure TForm1.BtSTMoveClick(Sender: TObject);
// Variables Globales STx_A0 => TPoint; ST_A => TStaticText.
Var
  Aux : TPoint ; Par1, Par2, N, I, IAzar : Integer;  S :String;
begin
S := '';
Repeat
    IAzar := Random(8) + 1 ;
    if Pos(IntToStr(IAzar), S ) = 0 then
       Insert( IntToStr(IAzar), S, Length(S) + 1) ;
Until Length(S) = 8   ;
   Edit1.Text := S;  // Muestra la serie de 8 digitos alfanum.
  // Código de intercambio de posiciones de los TStaticText según serie S
  for I := 1 to 4 do
    begin
     N := I + 4;
     Par1:= StrToInt(S[i] ); Par2:=  StrToInt(S[N] );
     Aux.X :=ST_A[Par1].Left;    Aux.Y :=ST_A[Par1].Top;
     ST_A[Par1].Left :=  ST_A[Par2].Left   ;
     ST_A[Par1].Top :=  ST_A[Par2].Top   ;
     ST_A[Par2].Left := Aux.X ;
     ST_A[Par2].Top := Aux.Y ;
    end;
end;

ElKurgan 21-02-2022 06:49:19

Gracias por compartir la solución

Saludos


La franja horaria es GMT +2. Ahora son las 20:31:42.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi