Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#10

AW: Suche nach Teilstring in einem Stringgrid

  Alt 8. Apr 2012, 23:02
Delphi-Quellcode:

Function FindInGrid(G:TStringGrid;var StartPoint:TPoint;Const Search:String;Next:Boolean):Boolean;
var
 R,C:Integer;
begin
  Result := False;
  for r := 0 to G.RowCount - 1 do
    for C := 0 to G.ColCount - 1 do
      begin
         IF Pos(Search,G.Cells[C,R]) >0 then
          if (not next) or ((r*G.ColCount + C) > ( StartPoint.y * G.ColCount + StartPoint.x )) then
              begin
                Result := True;
                StartPoint.y := r;
                StartPoint.x := c;
                EXIT;
              end;
      end;

end;
procedure TForm2.Button1Click(Sender: TObject);
var
 p:Tpoint;
 Next:Boolean;
begin
  p.X := 0;
  p.Y := 0;
  Next := False;
  while FindInGrid(StringGrid1,p,'Hallo',Next) do
    begin
      Next := True;
      Showmessage(StringGrid1.Cells[p.X,p.y] + Format(' Col: %d, Row: %d', [p.X,p.y]))
    end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat