Bonjour à Tous,


Je n'arrive pas à faire bouger le ScrollBar du RichEdit sur la ligne correspondante à l'occurrence trouvée.


Il semble que le classique :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
RichEdit1.Perform(EM_SCROLLCARET, 0, 0);
Soit ici sans aucun effet...


(Source : http://www.tek-tips.com/viewthread.cfm?qid=397710 )



Voici le code qui me donne du fil à retordre :
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
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
function TForm1.FindText( const SearchStr: string;
               StartPos, FindLength : LongInt; Options: TSearchTypes;
               SearchDown : Boolean = TRUE ): Integer;
var
Find: TFindText;
Flags: Word;
 
   begin
       with Find do
   begin
      chrg.cpMin := StartPos;
      chrg.cpMax := StartPos + FindLength;
      lpstrText := PChar(SearchStr);
         end;
 
Flags := 0;
 
if stWholeWord in Options then
   Flags := Flags or FT_WHOLEWORD
else
   Flags := Flags and not FT_WHOLEWORD;
 
if stMatchCase in Options then
   Flags := Flags or FT_MATCHCASE
else
   Flags := Flags and not FT_MATCHCASE;
 
if SearchDown then
   Flags := Flags OR $01
      else
   begin
   //Flags := Flags AND not $01;     // Search Up, just does not work !
   Flags := Flags OR $01
   end;
 
Result := -1;
 
if SearchDown then
   Result := SendMessage(RichEdit1.Handle, EM_FINDTEXT, Flags, LongInt(@Find))
else
   // Search Up, just does not work !  So just search down over and over
   // adjusting the start point backward.
   while (StartPos > -1) and (result = -1) do
      begin
      //result := RichEdit1.Perform(EM_FindText, Flags, LongInt(@Find));
      Result := SendMessage(RichEdit1.Handle, EM_FINDTEXT, Flags, LongInt(@Find));
      Dec(StartPos);
      Find.chrg.cpMin := StartPos;
    end;
end;
 
 
 
 
 
procedure TForm1.FindDialogFind(Sender: TObject);
   var
      FoundAt: LongInt;
      StartPos, FindLength, ToEnd : LongInt;
      TheFindOptions   : TFindOptions; 
      TheSearchTypes  : TSearchTypes;
    begin
      TheFindOptions := [];
      TheSearchTypes := [];
 
if frDown in FindDialog.Options then
     begin
        StartPos := RichEdit1.SelStart + RichEdit1.SelLength;
        FindLength := Length(RichEdit1.Text) - StartPos;
             end
         else
    begin
        StartPos := RichEdit1.SelStart;
        FindLength := 0;
     end;
 
         with Sender as TFindDialog do
     begin
         if frMatchCase in Options then
               TheSearchTypes := TheSearchTypes + [stMatchCase];
         if frWholeWord in Options then
               TheSearchTypes := TheSearchTypes + [stWholeWord];
             end;
        FoundAt := FindText(FindDialog.FindText, StartPos, FindLength, TheSearchTypes,  (frDown in FindDialog.Options) );
           if FoundAt <> -1 then
       begin
           RichEdit1.SetFocus;
             RichEdit1.SelStart := FoundAt;
             RichEdit1.SelLength := Length(FindDialog.FindText);
               end
            else
   MessageDlg('"' + FindDialog.FindText + '" not found.', mtInformation, [mbOk], 0);
end;


Merci d'avance de vos idées
(Je suis débutant)