Autor Beitrag
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Mo 30.12.02 17:31 
Hallo,

wie kann ich mit einen FindDialod in einen Memo suchen? Hab im Web folgendes gefunden, geht aber nicht! Plaziere einen FinDialog, einen Button und ein Memofeld auf dem Formular. Schreibe in das OnFind-Ereignis des FindDialoges folgednes:
ausblenden Quelltext
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:
procedure TForm1.FindDialog1Find(Sender: TObject);
var Buffer, Pos, tPointer : PChar;
    BuffLength            : Word;
begin
   With Sender as TFindDialog do
   begin
      GetMem(tPointer, Length(FindText) + 1);
      StrPCopy(tPointer, FindText);
      BuffLength:= Memo1.GetTextLen + 1;
      GetMem(Buffer,BuffLength);
      Memo1.GetTextBuf(Buffer,BuffLength);
      Pos:= Buffer + Memo1.SelStart + Memo1.SelLength;
      Pos:= StrPos(Pos, tPointer);
      if Pos = NIL then 
        MessageBeep(0)
      else
      begin
         Memo1.SelStart:= Pos - Buffer;
         Memo1.SelLength:= Length(FindText);
      end;
      FreeMem(tPointer, Length(FindText) + 1);
      FreeMem(Buffer,BuffLength);
      Memo1.SetFocus;
  end;
end;

Der FindDialog wird so aufgerufen:
ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
  FindDialog1.Execute;
end;


(30.12. 16:50 Tino) Code-Tags hinzugefügt.
Michael Stenzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 133


D3 Prof, D7 PE
BeitragVerfasst: Mi 01.01.03 03:12 
Hallo.
Die Procedure funktioniert ohne Änderung bei mir

Wenn Du den Text vom Anfang an Durchsuchen möchtes, setze
Memo1.SelStart auf 0.
Am besten machst Du das in der Procedure, die FindDialog.Execute
aufruft.

Hoffendlich hilft Dir das weiter.
Michael.