Bonjour,
Pour les besoins d'une petite application j'ai créé des procédures qui permettent de faire une saisie semi auto sur un TEdit.
Ces procédures fonctionnent avec une fichier contenant une série de mots.
(Pour les besoin de cette appli j'ai également un fichier "fich_index" qui regroupe tous les index des fichiers utilisés)
Procédure de proposition de mot en fonction des caractères saisis dans le Tedit
Procédure du TEdit OnChange
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure libelle(); var i,j,k:integer; nomtext,nomprovi,nom,mot:string; begin Seek(fich_index,1);Read(fich_index,enregindex); seek(fich_pref,enregindex.index_pref);Read(fich_pref,enregpref); if (enregpref.suggestion='oui') and (test_auto=0) then begin try nomprovi:='';nom:=''; for i:=pos('.del',nomfich) downto 1 do begin if ord(nomfich[i])<>92 then nomprovi:=nomprovi+char(ord(nomfich[i])); if ord(nomfich[i])=92 then Break; end; nom:=nomprovi;nomprovi:=''; for i:=length(nom) downto 2 do begin nomprovi:=nomprovi+char(ord(nom[i])); end; // ouverture ou création du fichier texte nomtext:=ExtractFilePath(Application.ExeName)+'dab00\'+ nomprovi +'mot.del'; AssignFile(fich_text,nomtext);Reset(fich_text); except AssignFile(fich_text,nomtext);ReWrite(fich_text); enregindex.index_mot:=0; Seek(fich_index,1);Write(fich_index,enregindex); end; // affichage de la liste des mots Seek(fich_index,1);Read(fich_index,enregindex); i:=enregindex.index_mot; if i>0 then begin compte.aide_saisie.Clear; for i:=1 to enregindex.index_mot do begin Seek(fich_text,i); Read(fich_text,enregtext); mot:=''; for j:=1 to length(compte.Edit1.Text) do begin mot:=mot+enregtext.mot[j]; end; if mot=trim(compte.Edit1.Text) then begin if compte.aide_saisie.Count<2 then compte.aide_saisie.Items.Add(enregtext.mot); for k:=1 to compte.aide_saisie.Count-1 do begin if enregtext.mot<>compte.aide_saisie.Items[k]then begin compte.aide_saisie.Left:=84; compte.aide_saisie.Top:=122; compte.aide_saisie.Visible:=true; compte.aide_saisie.Items.Add(enregtext.mot); end; end; end; end; end; // fin de if i>0 end; //fin de if enregpref.suggestion='oui' end; // fin de procédure
Procédure de saisie d'un mot dans la liste
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 procedure Tcompte.Edit1Change(Sender: TObject); begin if TEdit(Sender).Modified then Libelle; end;
Procédure du TEdit OnExit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 procedure Tcompte.aide_saisieClick(Sender: TObject); begin test_auto:=1; compte.Edit1.Text:=compte.aide_saisie.Items[compte.aide_saisie.ItemIndex]; aide_saisie.Clear; aide_saisie.Visible:=false; end;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure Tcompte.Edit1Exit(Sender: TObject); var i,fl:integer; begin Seek(fich_index,1);Read(fich_index,enregindex); // vérification du mot saisi fl:=0; for i:=1 to enregindex.index_mot do begin if trim(edit1.Text)= enregtext.mot then fl:=1; end; // si le mot n'a pas été trouvé on l'ajoute au fichier if (fl=0) and (length(edit1.Text)>2) then begin enregtext.mot:=trim(edit1.Text); enregindex.index_mot:=enregindex.index_mot+1; Seek(fich_index,1);Write(fich_index,enregindex); Seek(fich_text,enregindex.index_mot); Write(fich_text,enregtext); end; // fin de if fl=0 end;
Partager