Autor Beitrag
Lemartes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40


D7 Prof
BeitragVerfasst: Sa 28.08.04 21:25 
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:
procedure TForm1.FindDialog1Find(Sender: TObject);
var suchtext:string;
    r,c, found:integer; // 'r' steht für row (Zeile) und 'c' steh für col(Spalte)
begin
found:=0;
suchtext:=FindDialog1.FindText;
if (suchtext='')or(suchtext=' ') then else
begin
    For c:=0 to StringGrid1.ColCount-1 do
    For r:=0 to StringGrid1.RowCount-1 do
       If  finddialog1.frDisableMatchCase = true then //frDisablematchcase ist ihm völlig unbekannt...
       If (StringGrid1.Cells[c,r]=suchtext)  then
          if stringgrid1.selection.top = r then
          found:=found+1
          else
              begin
              found:=found+1;
              WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
              exit;
              end;
       else
       If ansistrlower(pchar(StringGrid1.Cells[c,r]))=pchar(suchtext)  then   //hierbei stürzt er ab!
          if stringgrid1.selection.top = r then
          found:=found+1
          else
              begin
              found:=found+1;
              WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
              exit;
              end;
       if found=0 then
       begin
       FindDialog1.CloseDialog;
       MessageDlg('" '+FindDialog1.FindText+'" wurde nicht gefunden', mtInformation, [mbOK],0);
       exit;
       end;
end;

end;


procedure TForm1.WaehleZeile(Zeile:Integer);
var newSel: TGridRect;

begin
    //Einstellung, dass man immer eine ganze Zeile auswählt:
    StringGrid1.Options := StringGrid1.Options + [goRowSelect];
    //Definition des selektierten Bereiches
    newSel.Left   := StringGrid1.FixedCols;
    newSel.Right  := StringGrid1.ColCount-1;
    newSel.Top    := Zeile;
    newSel.Bottom := Zeile;
    StringGrid1.Selection := newSel;
end;



ich hab nicht grade viel Ahnug, den Algorithmus hab ich ausm Netz, Fehler sind halt abstürzen wenn er strings ohne Groß- und Kleinschreibung vergleichen soll.
Außerdem wüsst ich gern, wie ich auslesen kann, welchen wert die veränderbaren Schaltflächen im Such-Dialog haben.
Außerdem wüsst ich gern, wie ich auch nach Wortteilen suchen kann.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 28.08.04 23:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
alt:
if (suchtext='')or(suchtext=' ') then else  
begin  
lol, der ist gut
neu:
if not((suchtext='')or(suchtext=' ')) then


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
alt:
If  finddialog1.frDisableMatchCase = true 

neu:
if frDisableMatchCase in finddialog1.options then


ansonsten ist der code grausam formatiert. war der wirklich so?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
    For c:=0 to StringGrid1.ColCount-1 do
     For r:=0 to StringGrid1.RowCount-1 do
{1}    if frDisableMatchCase in finddialog1.options then
{2}      If (StringGrid1.Cells[c,r]=suchtext)  then
           if stringgrid1.selection.top = r then
             found:=found+1
            else
             begin
               found:=found+1;
               WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen w
               exit;
             end;
          else   //dieses else gehört zum 2. if siehe bemerkung
       If ansistrlower(pchar(StringGrid1.Cells[c,r]))=pchar(suchtext)  then   //hierbei stürzt er ab!

Bemerkung: der If-Aufbau stimmt nicht. Das eine else gehört zum 2. If. Damit der programmablauf stimmt, muß es zum ersten if gehören, da fehlen einige begin end, die auch der Übersicht sicher gut tun würden. so läßt sich das nichtmal kompilieren.

Räum den code erstmal auf, formatier ihn ordentlich und setzt die begin und end richtig.
Anstatt dem ansistrlower kannst du auc ansilowercase nutzen, dort brauchst du den typecast zu pchar nicht, wär auch etwas übersichtlicher.
Zitat:

Außerdem wüsst ich gern, wie ich auslesen kann, welchen wert die veränderbaren Schaltflächen im Such-Dialog haben.

geht alles über die options, wie oben gezeigt
ausblenden Delphi-Quelltext
1:
if frDisableMatchCase in finddialog1.options then					



Zitat:

Außerdem wüsst ich gern, wie ich auch nach Wortteilen suchen kann.

geht über pos, Bsp in der hilfe und tausendmal im Forum. Pos unterscheidet zwischen groß und kleinschreibung, mußt dzu genauso beachten.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Lemartes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40


D7 Prof
BeitragVerfasst: Sa 28.08.04 23:54 
Zitat:
if (suchtext='')or(suchtext=' ') then else
begin
lol, der ist gut


fand ich auch, sonst hätt ichs ruaseditiert... (das hab ich mir net selbst ausgedacht...)

danke, das hilft mir weiter, aber:
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:
procedure TForm1.FindDialog1Find(Sender: TObject);
var suchtext:string;
    r,c, found:integer; // 'r' steht für row (Zeile) und 'c' steh für col(Spalte)

begin
row:=stringgrid1.selection.top;
found:=0;
suchtext:=FindDialog1.FindText;
if not(suchtext='')or(suchtext=' ') then
begin
    For c:=0 to StringGrid1.ColCount-1 do
      For r:=row to StringGrid1.RowCount-1 do
          if frMatchCase in finddialog1.options = true then
              If (StringGrid1.Cells[c,r]=suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else
                 begin
                 row:=stringgrid1.selection.top-1;
                 found:=found+1;
                 WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                 exit;
                 end
              else
          else
              If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else
                  begin
                  row:=stringgrid1.selection.top-1;
                  found:=found+1;
                  WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                  exit;
                  end;
if found=0 then
   begin
   row:=0;
   FindDialog1.CloseDialog;
   MessageDlg('" '+FindDialog1.FindText+'" wurde nicht gefunden', mtInformation, [mbOK],0);
   exit;
   end;
end;

end;


das ist ja ein bissle lang und ein großer teil unterscheidet sich nur durch eine zeile, lässt sich aber mit meinen kenntnissen nicht anders schreiben, da sonst wieder viele else falsch wären... geht das irgendwie?
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 29.08.04 07:47 
Was mir noch spanisch vorkommt ist das
Zitat:

row:=stringgrid1.selection.top;

sollte hier nicht auch
ausblenden Delphi-Quelltext
1:
stringgrid1.row:=stringgrid1.selection.top;					

stehen? wo kommt das row her? Muß ja ne globale variable sein...

in einer mir verständlicheren Form: Code ist aber ungetestet.
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:
var suchtext:string;
    r,c, found:integer; // 'r' steht für row (Zeile) und 'c' steh für col(Spalte)

begin
row:=stringgrid1.selection.top;
found:=0;
suchtext:=FindDialog1.FindText;
if not ((suchtext='')or(suchtext=' ')) then  //die äußere Klammer, also not(...Or...), muß sein!
  begin
    For c:=0 to StringGrid1.ColCount-1 do
     For r:=row to StringGrid1.RowCount-1 do
       begin
         if frMatchCase in finddialog1.options = true then
           begin
             //Groß und kleinschreibung wird berücksichtigt
             If (StringGrid1.Cells[c,r]=suchtext)  then
               begin
                 inc(found);  //stand bei der if stringgrid1.selection.top = r then in beiden Teilen drin; inc(found) ist das gleiche wie found:=found+1
                 if stringgrid1.selection.top <> r then //Bed umgedreht, da nur der else-zweig interessant war
                   begin
                     row:=stringgrid1.selection.top-1;
                     WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                     exit;
                   end;
               end;
           end
          else
           begin
             //Groß/Kleinschreibung wird nicht berücksichtigt
             If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext)  then
               begin
                 inc(found);
                 if stringgrid1.selection.top <> r then
                   begin
                     row:=stringgrid1.selection.top-1;
                     WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                     exit;
                   end;
               end;
           end;
      end;
    if found=0 then
       begin
         row:=0;
         FindDialog1.CloseDialog;
         MessageDlg('" '+FindDialog1.FindText+'" wurde nicht gefunden', mtInformation, [mbOK],0);
         //exit; das exit hier ist unnötig
       end;
  end;
end;

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Lemartes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40


D7 Prof
BeitragVerfasst: So 29.08.04 21:44 
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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
procedure TForm1.FindDialog1Find(Sender: TObject);
var suchtext:string;
    r,c,row, found:integer; // 'r' steht für row (Zeile) und 'c' steh für col(Spalte)

begin
found:=0;
suchtext:=FindDialog1.FindText;
if not(suchtext='') then
begin
if frdown in finddialog1.options = true then
    begin
    row:=stringgrid1.selection.top+1;
    For c:=0 to StringGrid1.ColCount-1 do
      For r:=row to StringGrid1.RowCount-1 do
          if frMatchCase in finddialog1.options = true then
              {If (StringGrid1.Cells[c,r]=suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else}
  //Kann es sein, dass dieser Fall jetzt unmöglich ist? Unten dann natürlich auch...
                 begin
                 {row:=stringgrid1.selection.top -1;}   //Kann es sein, dass diese Zeile total unnütz ist?
                 found:=found+1;
                 WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                 exit;
                 end
              else
          else
              If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else
                  begin
                  {row:=stringgrid1.selection.top -1; }
                  found:=found+1;
                  WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                  exit;
                  end
              else
    end
else
begin
row:=stringgrid1.selection.top-1;
For c:=0 to StringGrid1.RowCount-1 do
      For r:=row downto 0 do
          if frMatchCase in finddialog1.options = true then
              If (StringGrid1.Cells[c,r]=suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else
                 begin
                 {row:=stringgrid1.selection.top -1;}
                 found:=found+1;
                 WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                 exit;
                 end
              else
          else
              If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext)  then
                 if stringgrid1.selection.top = r then
                 found:=found+1
                 else
                  begin
                  {row:=stringgrid1.selection.top -1;}
                  found:=found+1;
                  WaehleZeile(r); //Prozedur, die bewirkt, dass eine bestimmte Zeile markiert wird, aufgerufen wird
                  exit;
                  end;
end;
if found=0 then
   begin
   row:=0;
   FindDialog1.CloseDialog;
   MessageDlg('" '+FindDialog1.FindText+'" wurde nicht gefunden', mtInformation, [mbOK],0);
   end;
end;

end;


hier is nochma die aktuelle Variante... und ja, row war eine globale Variable.

und wieder ein Problem:
nach text rauf und runter suchen geht. aber ich hab auch zahlen drin. nach unten geht es wunderbar, wenn ich aber eine zahl suche und zwar überhalb der jetzigen markierung in der liste (das sagt row eigentlich), findet er die nicht. wenn ich aber ein Wort eingebe, wird es gefunden. wie kann das kommen?