unit Protmain1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    Opti: TCheckBox;
    Button1: TButton;
    Warnlab: TLabel;
    ResLabel: TLabel;
    reslab1: TLabel;
    reslab2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure SortThem(Sender: TObject);
  private
    { Private declarations }
    PROCEDURE DeleteBox2;
    PROCEDURE CopyToListBox2;
    PROCEDURE BubbleSort( entries : Integer );
    PROCEDURE LabelOn;
    PROCEDURE UnusedFuncForDemo;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

PROCEDURE TForm1.DeleteBox2;
BEGIN
  Sleep(1000);
  ListBox2.Items.Clear;
END;

PROCEDURE TForm1.BubbleSort( entries : Integer );
VAR
  i      : Integer;
  s1, s2 : String;
  Found  : Boolean;
BEGIN
  Found := TRUE;
  WHILE TRUE DO BEGIN
    IF Found = FALSE THEN
      Break;
    Found := FALSE;
    i  := 0;
    s1 := ListBox2.Items.Strings[i];
    WHILE  i < entries - 1 DO BEGIN
      s2 := ListBox2.Items.Strings[i+1];
      IF s1 <= s2 THEN
        s1 := s2
      ELSE BEGIN
        ListBox2.Items.Strings[i]   := s2;
        ListBox2.Items.Strings[i+1] := s1;
        Found := True;
      END;
      INC(i);
    END;
  END;
END;

PROCEDURE TForm1.CopyToListBox2;
VAR
  i, n : Integer;
BEGIN
  n := ListBox1.Items.Count;
  FOR i := 0 TO n-1 DO
    ListBox2.Items.Add(ListBox1.Items.Strings[i]);
END;

PROCEDURE TForm1.LabelOn;
BEGIN
  {$IFDEF      PROFILE } ResLabel.Visible := TRUE;  {$ENDIF }
  {$IFNDEF     PROFILE } WarnLab.visible := TRUE;   {$ENDIF }
END;

procedure TForm1.SortThem(sender: TObject);
VAR
  n       : Integer;
begin
  Button1.Enabled := FALSE;
  ListBox2.Update;
  IF opti.Checked = TRUE THEN
    ListBox2.Items.BeginUpdate;
  DeleteBox2;
  CopyToListBox2;
  n := ListBox1.Items.Count;
  BubbleSort(n);
  IF opti.Checked = TRUE THEN
    ListBox2.Items.EndUpdate;
  Button1.Enabled := TRUE;
  LabelOn;
end;

PROCEDURE TForm1.UnusedFuncForDemo;
BEGIN
END;

end.
