Показать сообщение отдельно
  #3  
Старый 19.10.2011, 00:48
Аватар для angvelem
angvelem angvelem вне форума
.
 
Регистрация: 18.05.2011
Адрес: Омск
Сообщения: 3,970
Версия Delphi: 3,5,7,10,12,XE2
Репутация: выкл
По умолчанию

Немного изменил код и вывод делается в TImage, чтобы не было случайного стирания информации при перекрытии другими окнами или сворачивании:
Код:
unit Unit17;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  Math;

procedure TForm1.Button1Click(Sender: TObject);
var
  Buf       : array[0..59] of Integer;
  I, J, B,
  X, Y,
  Col, Row  : Integer;

  function NumberExists(Value : Integer) : Boolean;
  var
    I : Integer;
  begin
    Result := False;
    for I := Low(Buf) to High(Buf) do
      if Buf[i] = Value then
      begin
        Result := True;
        Break;
      end;
  end;

begin
  Randomize;
  Image1.Canvas.Brush.Color := clWhite;
  Image1.Canvas.FillRect(Image1.ClientRect);
  Col := StrToInt(edit1.Text);

  I := 0;
  FillChar(Buf, SizeOf(Buf), 0);
  // Заполним массив неповторяющимися числами
  while I <= High(buf) do
  begin
    B := Random(90) + 10;
    if NumberExists(B) then
      Continue
    else
    begin
      Buf[i] := B;
      inc(I);
    end;
  end;

  // найти максимальное число
  B := 0;
  for I := Low(Buf) to High(Buf) do
    if not odd(I) then
      B := Max(Buf[i], B);

  Edit2.Text := IntToStr(B);

  // Вывод
  Row := (High(Buf) + 1) div Col;
  for I := 0 to Row - 1 do
    for J := 0 to Col - 1 do
    begin
      Image1.Canvas.Font.Color := clBlack;
      if Buf[I * Col + J] = B then
        Image1.Canvas.Font.Color := clGreen;
      Image1.Canvas.TextOut(J * 35 + 10, I * 35 + 10, IntToStr(Buf[I * Col + J]));
      if Buf[I * Col + J] = B then
      begin
        X := J * 35 + 10;
        Y := I * 35 + 10;
        Image1.Canvas.Pen.Color := clRed;
        Image1.Canvas.Brush.Style := bsClear;
        Image1.Canvas.Rectangle(X - 6, Y - 4, X + 18, Y + 18);
        Image1.Canvas.Brush.Style := bsSolid;
      end;
    end;
end;

end.
__________________
Je venus de nulle part
55.026263 с.ш., 73.397636 в.д.
Ответить с цитированием