Selectionner plusieur Chaines

Résolu
louiwahl Messages postés 103 Date d'inscription vendredi 20 février 2004 Statut Membre Dernière intervention 16 mai 2019 - 5 sept. 2005 à 23:48
louiwahl Messages postés 103 Date d'inscription vendredi 20 février 2004 Statut Membre Dernière intervention 16 mai 2019 - 6 sept. 2005 à 00:23
Bjr



Dans mon programe j'ai une fonction qui cherche des Chaine et les change de couleur quand il les trouve

mais si dans mon text il y a plusieur fois le mot rechercher il ne m'en trouve qu'un il faudrais qu'il les trouvent tous





voici la partie de mon code de recherche



Procedure TForm1.chercheMots;

var

FoundAt: LongInt;

I, StartPos,ToEnd: Integer;

begin

with MemoEleve do

begin

For I := 0 to ListBox1.Items.Count-1 do

begin

Edit1.Text:= ListBox1.Items.Strings[I];

StartPos :=0;

ToEnd :=Length(Text)-StartPos;

FoundAt :=FindText(Edit1.Text,StartPos,ToEnd,[stMatchCase]);

if FoundAt <>-1 then

begin

SelStart :=FoundAt;

SelLength :=Length(Edit1.Text);

selattributes.Color := clRed; end;

end;

end;

end;



procedure TForm1.BitBtn3Click(Sender: TObject);

begin

ListBox1.Items.Add(EditMot1.Text);

ListBox1.Items.Add(EditMot2.Text);

ListBox1.Items.Add(EditMot3.Text);

ListBox1.Items.Add(EditMot4.Text);

ChercheMots;

end;



si il y a des idees

Louis

2 réponses

ni69 Messages postés 1418 Date d'inscription samedi 12 juin 2004 Statut Membre Dernière intervention 5 juillet 2010 12
6 sept. 2005 à 00:16
Voici le code qu'il te faut :



procedure TForm1.chercheMots;

var

i, StartPos,ToEnd: Integer;


begin


with MemoEleve do begin

For i := 0 to ListBox1.Items.Count-1 do begin


Edit1.Text: = ListBox1.Items.Strings[i];


StartPos := -1;

repeat // ON REPETE CE CODE...
ToEnd : = Length(Text) - StartPos;

StartPos := FindText(Edit1.Text,StartPos+1,ToEnd,[stMatchCase]); // Recherche le mot contenu dans Edit1.Text dans le Memo à partir du (StartPos+1)ème caractère
if StartPos <> -1 then begin // Si on a trouvé quelque-chose


SelStart : = StartPos;


SelLength := Length(Edit1.Text);


SelAttributes.Color := clRed; // On colore le texte

end;

until StartPos =-1; // ...JUSQU'A CE QUE StartPos VAILLE -1, C'EST A DIRE QUE LE MOT N'A PAS (OU PLUS) ETE TROUVE DANS LE MEMO

end;

end;

end;



@+
Bonne Prog'
Nico [www.ni69.new.fr]
<hr size="2" width="100%">
N'oubliez pas de cliquer sur Réponse acceptée lorsque la réponse vous convient !
3
louiwahl Messages postés 103 Date d'inscription vendredi 20 février 2004 Statut Membre Dernière intervention 16 mai 2019
6 sept. 2005 à 00:23
Merci beaucoup cela marche tres bien

je vais regarder ce a quoi je n'est pas pense

Merci encore et A+

Louis
0
Rejoignez-nous