Autor Beitrag
Hochhaus
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 662
Erhaltene Danke: 8

Windows 7
Delphi XE2
BeitragVerfasst: Mo 14.10.13 10:38 
Hallo allerseits !

um in einem RichEdit zu suchen und zu ersetzen, verwende ich folgenden Code:

ausblenden volle Höhe Delphi-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:
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:
Function FindInRichEdit(const AFindDialog: TFindDialog;
  const ATargetRichEdit: TRichEdit): Boolean;
Var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
  mySearchTypes: TSearchTypes;
Begin
  mySearchTypes := [];
  If frMatchCase in AFindDialog.Options then
    mySearchTypes := mySearchTypes + [stMatchCase];
  If frWholeWord in AFindDialog.Options then
    mySearchTypes := mySearchTypes + [stWholeWord];
  {* Begin the search after the current selection, if there is one. *}
  {* Otherwise, begin at the start of the text. *}
  If ATargetRichEdit.SelLength <> 0 then
    StartPos := ATargetRichEdit.SelStart + ATargetRichEdit.SelLength
  Else
    StartPos := 0;
  {* ToEnd is the length from StartPos through the end of the
    text in the rich edit control. *}

  ToEnd := Length(ATargetRichEdit.Text) - StartPos;
  FoundAt := ATargetRichEdit.FindText(AFindDialog.FindText, StartPos, ToEnd,
   mySearchTypes);
  Result := FoundAt <> -1;
  If Result then
  Begin
    ATargetRichEdit.SetFocus;
    ATargetRichEdit.SelStart := FoundAt;
    ATargetRichEdit.SelLength := Length(AFindDialog.FindText);
  End;
End{* Function *}



Procedure TFrmChild.FindX(Sender: TObject);
Begin
  If Not FindInRichEdit(Sender as TFindDialog, RichEdit1) then
    Beep;
End{* Procedure *}



Procedure TFrmChild.ReplaceX(Sender: TObject);
Var
  ReplaceDlg: TReplaceDialog;
Begin
  ReplaceDlg := Sender As TReplaceDialog;
  While FindInRichEdit(ReplaceDlg, RichEdit1) Do
  Begin
    RichEdit1.SelText := ReplaceDlg.ReplaceText;
    RichEdit1.SelStart := RichEdit1.SelStart - Length(ReplaceDlg.ReplaceText);
    RichEdit1.SelLength := Length(ReplaceDlg.ReplaceText);
    If not(frReplaceAll in ReplaceDlg.Options) then
      Break;
  End;
End{* Procedure *}


Was muss ich ändern, um in einem TMemo zu suchen ? Besten Dank für jede Antwort !


Hochhaus
baumina
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 305
Erhaltene Danke: 61

Win 7
Delphi 10.2 Tokyo Enterprise
BeitragVerfasst: Mo 14.10.13 10:54 

Für diesen Beitrag haben gedankt: Hochhaus
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 14.10.13 10:54 
...einen Text im Memofeld finden

www.swissdelphicente...showcode.php?id=2136

Für diesen Beitrag haben gedankt: Hochhaus