unit Main;

interface

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

type
  TMainForm = class(TForm)
    Memo1: TMemo;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);

  private
	 procedure Sort(var A : array of Integer; AHigh : Integer);
	 procedure Start();

  public
    procedure Koniec();

  end;

var
  MainForm: TMainForm;

implementation
{$R *.dfm}
{------------------------------------------------------------------------------}
procedure TMainForm.BitBtn1Click(Sender: TObject);
begin
	Koniec();
end;

procedure TMainForm.BitBtn2Click(Sender: TObject);
begin
	Start();
end;

procedure TMainForm.FormShow(Sender: TObject);
begin
	Memo1.Clear();
end;

procedure TMainForm.Koniec();
begin
	if Application.MessageBox('Koniec pracy', 'Uwaga', MB_YESNO or MB_ICONEXCLAMATION) = IDYES then
   begin
      Application.Terminate();
   end;
end;

procedure TMainForm.Start();
var
   Tab : array[0..9] of Integer;
   lp  : Integer;
   tt  : Integer;

begin
	Memo1.Clear();

   tt := 10;
	for lp := Low(Tab) to High(Tab) do
   begin
		Tab[lp] := tt;
      Dec(tt);
   end;

   Memo1.Lines.Add('zawartość Tab:');
	// zawartosc tablicy na ekran
   // to samo co
   // for lp := 0 to 9 do
	for lp := Low(Tab) to High(Tab) do
   begin
      Memo1.Lines.Add(IntToStr(Tab[lp]));
   end;
   Memo1.Lines.Add(' ');
   
   // Sort(Tablica, MaxElIndex);
	Sort(Tab, High(Tab));

   Memo1.Lines.Add('Tab posortowana:');

	for lp := Low(Tab) to High(Tab) do
   begin
      Memo1.Lines.Add(IntToStr(tab[lp]));
   end;
end;

procedure TMainForm.Sort(var A : array of Integer; AHigh : Integer);
var
	i : Integer;
	j : Integer;
	t : Integer;

begin
	I := 0;
	J := 0;
	T := 0;

	for i := AHigh downto 0 do
   begin
   	for J := 0 to AHigh-1 do
      begin
      	if A[J] > A[J + 1] then
         begin
         	T := A[J];
            A[J] := A[J + 1];
            A[J + 1] := T;
         end;
      end;
   end;
end;

end.

