| Autor |
Beitrag |
Lemartes
      
Beiträge: 40
D7 Prof
|
Verfasst: Sa 28.08.04 21:25
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; 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 If (StringGrid1.Cells[c,r]=suchtext) then if stringgrid1.selection.top = r then found:=found+1 else begin found:=found+1; WaehleZeile(r); exit; end; else If ansistrlower(pchar(StringGrid1.Cells[c,r]))=pchar(suchtext) then if stringgrid1.selection.top = r then found:=found+1 else begin found:=found+1; WaehleZeile(r); 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 StringGrid1.Options := StringGrid1.Options + [goRowSelect]; 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
      
Beiträge: 2266
Erhaltene Danke: 4
Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
|
Verfasst: Sa 28.08.04 23:15
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 |
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?
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 if frDisableMatchCase in finddialog1.options then If (StringGrid1.Cells[c,r]=suchtext) then if stringgrid1.selection.top = r then found:=found+1 else begin found:=found+1; WaehleZeile(r); exit; end; else If ansistrlower(pchar(StringGrid1.Cells[c,r]))=pchar(suchtext) then |
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
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 
      
Beiträge: 40
D7 Prof
|
Verfasst: 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:
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; 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); 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); 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
      
Beiträge: 2266
Erhaltene Danke: 4
Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
|
Verfasst: So 29.08.04 07:47
Was mir noch spanisch vorkommt ist das
| Zitat: |
row:=stringgrid1.selection.top;
|
sollte hier nicht auch
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.
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; 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 begin if frMatchCase in finddialog1.options = true then begin If (StringGrid1.Cells[c,r]=suchtext) then begin inc(found); if stringgrid1.selection.top <> r then begin row:=stringgrid1.selection.top-1; WaehleZeile(r); exit; end; end; end else begin 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); exit; end; end; end; end; if found=0 then begin row:=0; FindDialog1.CloseDialog; MessageDlg('" '+FindDialog1.FindText+'" wurde nicht gefunden', mtInformation, [mbOK],0); end; end; end; |
_________________ Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
|
|
Lemartes 
      
Beiträge: 40
D7 Prof
|
Verfasst: So 29.08.04 21:44
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; 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 begin found:=found+1; WaehleZeile(r); exit; end else else If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext) then if stringgrid1.selection.top = r then found:=found+1 else begin found:=found+1; WaehleZeile(r); 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 found:=found+1; WaehleZeile(r); exit; end else else If ansilowercase(StringGrid1.Cells[c,r])= ansilowercase(suchtext) then if stringgrid1.selection.top = r then found:=found+1 else begin found:=found+1; WaehleZeile(r); 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?
|
|
|