Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 20-05-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 23
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
bulc,

Cita:
Empezado por bulc
...Me gustaría saber si la clausula Randomize se debe poner en el evento OnCreate o en el procedimiento mismo...


Cita:
Empezado por RAD Studio VCL Reference
Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.

Do not combine the call to Randomize in a loop with calls to the Random function. Typically, Randomize is called only once, before all calls to Random
Revisa esta información:
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 21-05-2015 a las 02:22:17.
Responder Con Cita
  #2  
Antiguo 20-05-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola bulc.

La cantidad de imágenes involucradas, no me genera ningún tipo de problema. En este ejemplo uso 24 imágenes:
Código Delphi [-]
...
implementation

var
  vImage : array of TImage;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  SetLength(vImage, 24);
  for i := 0 to ImageList1.Count-1 do
  begin
    vImage[i] := TImage(FindComponent('Image'+IntToStr(i+1)));
    vImage[i].Picture.Bitmap.Width  := 32;
    vImage[i].Picture.Bitmap.Height := 32;
    ImageList1.GetBitmap(i, vImage[i].Picture.Bitmap );
  end;
  Randomize;
end;

procedure TForm1.btnMergeClick(Sender: TObject);
var
  a,b,i: Integer;
  p: TPoint;
begin
  for i := Low(vImage) to High(vImage) do
  begin
    a   := Random(24);
    b   := Random(24);
    p.X := vImage[a].Left;
    p.Y := vImage[a].Top;
    vImage[a].Left := vImage[b].Left;
    vImage[a].Top  := vImage[b].Top;
    vImage[b].Left := p.X;
    vImage[b].Top  := p.Y;
  end;
end;

Salida:


Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #3  
Antiguo 21-05-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 23
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
bulc,

Cita:
Empezado por bulc
...Me gustaría saber si la clausula Randomize se debe poner en el evento OnCreate o en el procedimiento mismo...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, jpeg, ExtCtrls, Math, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Shuffle : Boolean;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   Image : Array of Integer;
   R1, R2 : Integer;
   P : TPicture;
   i : Integer;

begin

   for i := 0 to ComponentCount - 1 do
      if (FindComponent('Image' + IntToStr(i+1)) is TImage) then
      begin
         SetLength(Image, Length(Image)+1);
         Image[High(Image)] := i;
      end;

   RandSeed := GetTickCount; // Randomize; {Función Equivalente}

   Shuffle := True;

   while Shuffle do
   begin

      Application.ProcessMessages;

      R1 := RandomRange(Low(Image),High(Image)+1); // R1 := Random(High(Image)+1); {Función Equivalente}
      R2 := RandomRange(Low(Image),High(Image)+1); // R2 := Random(High(Image)+1); {Función Equivalente}

      P := TPicture.Create;
      P.Assign(TImage(Components[Image[R1]]).Picture.Graphic);
      TImage(Components[Image[R1]]).Picture.Assign(TImage(Components[Image[R2]]).Picture.Graphic);
      TImage(Components[Image[R2]]).Picture.Assign(P.Graphic);
      P.Free;

      Sleep(100);

   end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   Shuffle := False;
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Cambia de forma aleatoria 8 imágenes contenidas en componentes TImage por medio de las funciones RandSeed y RandomRange, como se muestra en la siguiente imagen:



Nota: El código sugerido funciona análogamente con las funciones Randomize y Random.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 21-05-2015 a las 04:49:47.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Uso de Random arespremium OOP 5 12-08-2007 21:48:39
Random() altp .NET 3 27-11-2006 11:59:45
random chechu Varios 6 24-11-2005 20:09:45
random edulp Varios 1 24-10-2005 02:17:39
Random!! Alejandro Horns Varios 1 13-12-2004 16:37:39


La franja horaria es GMT +2. Ahora son las 18:13:25.


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