unit slistform;

{$mode objfpc}{$H+}

interface

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

const specimen: string = 'Enter by the narrow gate; for the wide gate has a broad' +
	' road which leads to destruction and there are many people going that way. The' +
	' narrow gate and the hard road lead to life and only a few find it.';

type
	TForm1 = class(TForm)
		LBWords: TListBox;
		LCount: TLabel;
		Mdisplay: TMemo;
		procedure FormCreate(Sender: TObject);
	end;

var
	Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
	sl, noDuplicates: TStringList;
	j: integer;
begin
	MDisplay.Text := specimen;
	sl := TStringList.Create;
	noDuplicates := TStringList.Create;
	try
		sl.CommaText := specimen;
		sl.Sort;

		for j := 0 to sl.Count-1 do
			if (noDuplicates.indexOf(sl[j]) > 0) then noDuplicates.Add(sl[j]);

		LBWords.Items.AddStrings(noDuplicates);
		LCount.Caption := Format(
			'Specimen text has %d words of which %d are unique',
			[sl.Count, noDuplicates.Count]
		);
	finally
		sl.Free;
		noDuplicates.Free;
	end;
end;

end.

