Autor Beitrag
Diskette
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
Delphi 5 Pers., Borland Developer 2006 Prof.
BeitragVerfasst: Sa 16.06.07 19:50 
Hi,
zuerst mal mein Code:

Suchen-Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TSearch.Button1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  stelle := 1;
  tPos := PosEx(Search.SuchNach.text, Main.RichEdit1.Lines.text, stelle);
  LenLookFor := Length(search.SuchNach.text);
  stelle := 1;
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  stelle := stelle + 1;
  Search.Close;
end;


Weitersuchen-Funktion
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TMain.Weitersuchen1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  tPos := 0;
  LenLookFor := 0;
  tPos := PosEx(Search.SuchNach.text, Main.RichEdit1.Lines.text, stelle);
  LenLookFor := Length(search.SuchNach.text);
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  stelle := stelle + 1;
end;


Struktur meines Projekts:
2 Forms (main, Search)
Auf Main-Form ist ein RichtEdit (RichEdit1)
Auf Search-Form ist ein Text-Feld (SuchNach) und ein Button (Button1)


So, das Problem ist, auch wenn der Zähler "stelle" erhöht wird, bekomme ich in der Funktion "weitersuchen" immer nur das 2te vorkommen angezeigt... Der Counter wird auch erhöht, trotzdem das gleiche ergebnis...

Nochmal aufgespalten:
test <<< bei Suchen makiert (Stelle := 1;)
test <<< bei jedem ausführen von weitersuchen makiert (nur wenn suchen einmal ausgeführt wurde) (immer wenn stelle größer als 1 is)
test <<< müsste bei stelle := 3; makiert sein
test <<< müsste bei stelle := 4; makiert sein
test <<< müsste bei stelle := 5; makiert sein


Hoffe es findet jemand das Problem,
LG und sry es is ein wenig unübersichtlich,
Diskette
bflegel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP, Win 7, BS2000
D5
BeitragVerfasst: Sa 16.06.07 21:51 
user profile iconDiskette hat folgendes geschrieben:

Suchen-Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TSearch.Button1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  stelle := 1;
  tPos := PosEx(Search.SuchNach.text, Main.RichEdit1.Lines.text, stelle);
  LenLookFor := Length(search.SuchNach.text);
  stelle := 1;
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  stelle := stelle + 1;
  Search.Close;
end;


Weitersuchen-Funktion
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TMain.Weitersuchen1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  tPos := 0;
  LenLookFor := 0;
  tPos := PosEx(Search.SuchNach.text, Main.RichEdit1.Lines.text, stelle);
  LenLookFor := Length(search.SuchNach.text);
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  stelle := stelle + 1;
end;



Hi,

ich hab mir den Text zwar nicht genau angesehen, aber hast Du nicht ein kleines Problem:
Am Ende der Suchen-Procedure machst Du einen Search.Close und schliesst damit die Form. Beim Weitersuchen verwendest Du aber die Variable Search.SuchNach.txt

Diese dürfte aber doch nach dem Schließen des Fensters nicht mehr existent sein?

Bye
bflegel

_________________
I know all the jokes about my name
Diskette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
Delphi 5 Pers., Borland Developer 2006 Prof.
BeitragVerfasst: So 17.06.07 10:02 
Okay,
danke aber daran liegts net, habe das mal anders Probiert mit gleichem Ergebnis...

Suchen-Funktion
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TSearch.Button1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  Unit1.stelle := 1;
  tPos := PosEx(Search.SuchNach.text, Main.RichEdit1.Lines.text, Unit1.stelle);
  LenLookFor := Length(search.SuchNach.text);
  stelle := 1;
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  Unit1.stelle := Unit1.stelle + 1;
  Unit1.SuchText := Search.SuchNach.text;
  Search.Close;
end;


Weitersuchen-Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TMain.Weitersuchen1Click(Sender: TObject);
var
  tPos, LenLookFor : integer;
begin
  tPos := 0;
  LenLookFor := 0;
  tPos := PosEx(SuchText, Main.RichEdit1.Lines.text, stelle);
  LenLookFor := Length(search.SuchNach.text);
  if tPos > 0 then
  begin
    Main.RichEdit1.SelStart := tPos - 1;
    Main.RichEdit1.SelLength := LenLookFor;
  end;
  stelle := stelle + 1;
end


Das war der angepasste Code,
falls jemand ne Idee hat, schicke ich ihm das Projekt nochmal per P.N.,
will es aber, da es sich um ein Gemeinschaftsprojekt (geschlossene Gruppe) nicht öffentlich Zeigen.
LG,
Diskette
Diskette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
Delphi 5 Pers., Borland Developer 2006 Prof.
BeitragVerfasst: So 17.06.07 14:30 
Habe das Problem gefunden.
Anders als in der Dokumentation ist der Syntax der Function PosEx:
PosEx(Zu suchender Text: String, Text in dem gesucht werden soll: String, Zeichen ab dem gesucht werden soll: Integer);

Demnach muss in weitersuchen die Zeile 14 so heißen:
stelle := tPos + LenLookFor;

Lg,
Diskette