Показать сообщение отдельно
  #8  
Старый 05.06.2010, 09:41
Аватар для dr. F.I.N.
dr. F.I.N. dr. F.I.N. вне форума
I Like it!
 
Регистрация: 12.12.2009
Адрес: Россия, г. Новосибирск
Сообщения: 663
Версия Delphi: D6/D7
Репутация: 26643
По умолчанию

Код:
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 360
  Height = 191
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 80
    Top = 24
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
  end
  object Button2: TButton
    Left = 64
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
  end
  object Button3: TButton
    Left = 48
    Top = 88
    Width = 75
    Height = 25
    Caption = 'Button3'
    TabOrder = 2
  end
  object Button4: TButton
    Left = 32
    Top = 120
    Width = 75
    Height = 25
    Caption = 'Button4'
    TabOrder = 3
  end
  object Button5: TButton
    Left = 208
    Top = 120
    Width = 123
    Height = 25
    Caption = 'Зарандомить :)'
    TabOrder = 4
    OnClick = Button5Click
  end
end
Код:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ShowRandom(StartTop, Offset: Integer; ObjList: TList);
var
  x, i: Integer;
  tempList: TList;
begin
  if ObjList.Count = 0 then Exit;
  tempList := TList.Create;
  tempList.Assign(ObjList);
  x := StartTop;
  while tempList.Count > 0 do
  begin
    i := Random(tempList.Count);
    TControl(tempList.Items[i]).Top := x;
    Inc(x, Offset);
    tempList.Delete(i);
  end;
  tempList.Free;
end;



procedure TForm1.Button5Click(Sender: TObject);
var
  Lst: TList;
begin
  Lst := TList.Create;
  Lst.Add(Button1);
  Lst.Add(Button2);
  Lst.Add(Button3);
  Lst.Add(Button4);
  ShowRandom(24, 32, Lst);
  Lst.Clear;
  Lst.Free;
end;

end.
Ответить с цитированием