maskofa

StringGrid function search

Jul 26th, 2021 (edited)
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | None | 0 0
  1. {TStringGrid}
  2. function  TStringGrid.Search(AText: String; AStart: TPoint): TPoint;
  3. var
  4.   iii: Integer;
  5.   jjj: Integer;
  6. begin
  7.   result.X := 0;
  8.   result.Y := 0;
  9.  
  10.   //baris pertama;
  11.   for iii := AStart.X to ColCount - 1 do
  12.   begin
  13.     if Pos(LowerCase(AText), LowerCase(Cells[iii, AStart.Y])) > 0 then
  14.     begin
  15.       Col := iii;
  16.       Row := AStart.Y;
  17.  
  18.       result := SetSearchResult(Point(iii, AStart.Y));
  19.       Repaint;
  20.       exit;
  21.     end;
  22.   end;
  23.  
  24.   //baris berikutnya;
  25.   for iii := 0 to ColCount - 1 do
  26.   begin
  27.     for jjj := AStart.Y + 1 to RowCount - 1 do
  28.  
  29.     if Pos(LowerCase(AText), LowerCase(Cells[iii, jjj])) > 0 then
  30.     begin
  31.       Col := iii;
  32.       Row := jjj;
  33.  
  34.       result := SetSearchResult(Point(iii, jjj));
  35.       Repaint;
  36.       exit;
  37.     end;
  38.   end;
  39. end;
  40.  
  41. function  TStringGrid.SetSearchResult(FPoint: TPoint): TPoint;
  42. begin
  43.   //posisi normal;
  44.   result := Point(FPoint.X + 1, FPoint.Y);
  45.  
  46.   //posisi column di ujung;
  47.   if FPoint.X = ColCount then
  48.   result := Point(0, FPoint.Y + 1);
  49.  
  50.   //posisi diakhir grid;
  51.   if (FPoint.X = ColCount) and (FPoint.Y = RowCount) then
  52.   result := Point(0, 0);
  53. end;
Add Comment
Please, Sign In to add comment