1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
ListeFiltre:TStringList;
function DebutMot(Index,Longueur:Integer):string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses strutils;
function EnleverAccents(S: string): string;
const
CHAINE_DEPART = 'àäâãçéèêëìïîôöòûüùÿÁÀÄÂÃÉÈÊËÍÎÌÔÖÒÓÕÜÛÙÚÝ';
CHAINE_ARRIVEE = 'aaaaceeeeiiiooouuyyAAAAAEEEEIIIOOOOOUUUUY';
var
i, Position: Integer;
begin
for i:=1 to Length(S) do
begin
Position:=Pos(S[i],CHAINE_DEPART);
if Position > 0 then // Si c'est accentué ...
S[i]:=CHAINE_ARRIVEE[Position]; // On met le carac correspondant non accentué.
end;
Result:=S;
end;
function TForm1.DebutMot(Index,Longueur:Integer):string;
var UnMot:string;
begin
UnMot:=ListeFiltre.Strings[Index];
result:=EnleverAccents(Copy(UnMot,1,Longueur));
end;
procedure TForm1.Edit1Change(Sender: TObject);
var i,ALength:integer;
AText:string;
begin
ListBox1.clear;
RichEdit1.Clear;
AText:=EnleverAccents(Edit1.Text);
ALength:=length(AText);
Form1.cursor:=crHourGlass;
Application.ProcessMessages;
if ALength=0 then
begin
// ListBox1.Items.AddStrings(ListeFiltre);
Form1.cursor:=crDefault;
Exit;
end;
i:=0;
while ((i<ListeFiltre.Count-1) and (DebutMot(i,ALength)<AText))
do Inc(i);
while ((i<ListeFiltre.Count-1) and (DebutMot(i,ALength)=AText)) do
begin
ListBox1.Items.Add(ListeFiltre.Strings[i]);
Application.ProcessMessages;
Inc(i);
end;
Form1.cursor:=crDefault;
Application.ProcessMessages;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ListeFiltre.LoadFromFile('mots.txt');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListeFiltre:=TStringList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ListeFiltre.Free;
end;
end. |
Partager