Autor Beitrag
rafi@work
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 15.11.04 10:04 
Hallo zusammen!

Ich bräuchte eine Suchfunktion, z.B. die, welche im Notepad mit CTRL+F aufgerufen werden kann. Das ganze wäre für die Komponente TRichEdit. Gibt es dafür eine Komponente?

Gruss
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 15.11.04 11:00 
Nö, aber zumindest den Dialog gibts vorgefertigt. Und so schwer ist es ja nicht, einen Text zu durchsuchen und einen Abschnitt zu markieren. Sinngemäß:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
with RichEdit do
begin
  SelStart:=Pos(SuchString,Copy(Text,Startoffset,Length(Text)));
  SelLength:=Length(SuchString);
end;

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 15.11.04 11:51 
hallo .Chef

Danke, aber es sollte dann so sein, das wenn man suchen klickt, es das Wort markiert und zur Stelle scrollt. Und wenn man weiter auf Suchen klickt, das nächste Wort anmarkiert wird und zur Stelle scrollt. usw...

Siehe Suchfunktion im notepad.exe.

Gruss
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mo 15.11.04 12:14 
Weiß ich. Mein Code macht genau das. Ok, zur Zeile musst du noch scrollen. Das geht z.B. mit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  a : Integer;
begin
  with RichEdit do
  begin
    a:=SendMessage(Handle,EM_LINEFROMCHAR,SelStart,0);
    Perform(EM_LINEINDEX,a,0);
    Perform(EM_SCROLLCARET,0,0);
  end;

Ungetestet.

Ein bißchen Kreativität beim Einbinden in dein Programm musst du schon auch an den Tag legen. Aber alle elementaren "Bauteile" siehst du hier.

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 15.11.04 13:10 
Hallo

Ist StartOffset eine Integer Variable?
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mo 15.11.04 13:33 
rafi@work hat folgendes geschrieben:
Hallo

Ist StartOffset eine Integer Variable?
Jap, siehe auch die Hilfe zu Copy. Sie gibt an, wo die Suche beginnen soll (hab ich jetzt einfach so geraten ;)).

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 15.11.04 14:54 
Danke beiden für die Hilfe!!

Ich habe es mit FindDialog1 realisiert. Kannte diese Komponente bis anhin gar nicht :roll:

ausblenden 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:
procedure TFormTestOutput.FindDialog1Find(Sender: TObject);
var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
begin
  with RichEditTestingOutput do
  begin
    { Suche hinter aktueller Markierung beginnen (falls vorhanden), }
    { andernfalls am Textanfang starten. }
    if SelLength <> 0 then

      StartPos := SelStart + SelLength
    else

      StartPos := 0;

    { ToEnd ist die Länge von StartPos bis zum Textende im RTF-Eingabefeld }

    ToEnd := Length(Text) - StartPos;

    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
    end;
  end;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TFormTestOutput.Button2Click(Sender: TObject);
begin
  FindDialog1.Position := Point(RichEditTestingOutput.Left + RichEditTestingOutput.Width, RichEditTestingOutput.Top);
  FindDialog1.Execute;
end;


Damit funktionierts auch wunderbar :D (Ist ja auch das Beispiel von der Delphi-Help ;))

Grüsse