home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 January / Chip_2000-01_cd.bin / zkuste / Delphi / nastroje / browutil.exe / COMPNT / FINDDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-06-09  |  4.2 KB  |  157 lines

  1. unit FindDlg;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, DB, DBTables ;
  8.  
  9. type
  10.   TFindDlg = class(TReplaceDialog)
  11.   private
  12.     { Private declarations }
  13.     FDataSet : TDataSet;
  14.     FFieldNames : String;
  15.     FFound : Boolean;
  16.     FAbortProcess : Boolean;
  17.     FAutoEdit : Boolean;
  18.     procedure Find(Sender : TObject);
  19.     procedure Replace(Sender : TObject);
  20.   protected
  21.     { Protected declarations }
  22.     procedure DoClose; override;
  23.   public
  24.     { Public declarations }
  25.     constructor Create(AOwner: TComponent); override;
  26.     destructor Destroy; override;
  27.   published
  28.     { Published declarations }
  29.     property TableName : TDataSet read FDataSet write FDataSet;
  30.     property FieldNames : String read FFieldNames write FFieldNames;
  31.     property AutoEdit : Boolean read FAutoEdit write FAutoEdit;
  32.   end;
  33.  
  34. procedure Register;
  35.  
  36. implementation
  37.  
  38. constructor TFindDlg.Create(AOwner: TComponent);
  39. begin
  40.   inherited Create(AOwner);
  41.   OnFind := Find;
  42.   OnReplace := Replace;
  43. //  OnClose := Close;
  44.   FFound := False;
  45.   FAbortProcess := False;
  46. end;
  47.  
  48. { Find Window Position
  49.   GetWindowRect(FindDialog1.Handle,Rect1);
  50.   nWidth := Rect1.Right - Rect1.Left;
  51.   nHeight := Rect1.Bottom - Rect1.Top;
  52.   SetWindowPos(FindDialog1.Handle,0,(Self.Width-nWidth)+Self.Left,(Self.Height-nHeight)+(Self.Top+10),0,0,
  53.     SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  54. }
  55. procedure TFindDlg.DoClose;
  56. begin
  57.   inherited;
  58.   FAbortProcess := True;
  59. end;
  60.  
  61. procedure TFindDlg.Find(Sender : TObject);
  62. var
  63.   sFindText : String;
  64.   I : Integer;
  65.   SearchField : TField;
  66.   tblFind : TTable;
  67. begin
  68.   tblFind := TTable(TableName);
  69.   sFindText := FindText;
  70.   if tblFind.EOF then begin
  71.     tblFind.First;
  72.     FFound := False;
  73.   end;
  74.   tblFind.DisableControls;
  75.   if FFound then
  76.     if (frDown in Options) then
  77.       tblFind.Next
  78.     else
  79.       tblFind.Prior;
  80.   FFound := False;
  81.   if frDown in Options then
  82.     while not tblFind.EOF do begin
  83.       for I := 0 to tblFind.FieldDefs.Count - 1 do begin
  84.         Application.ProcessMessages;
  85.         if FAbortProcess then begin
  86.           FAbortProcess := False;
  87.           tblFind.EnableControls;
  88.           Abort;
  89.         end;
  90.         if (tblFind.FindField(tblFind.FieldDefs.Items[I].Name) <> nil) then begin
  91.           SearchField := tblFind.FindField(tblFind.FieldDefs.Items[I].Name);
  92.           if (Pos(UpperCase(sFindText),UpperCase(SearchField.AsString)) > 0) then begin
  93.             FFound := True;
  94.             if FAutoEdit then
  95.               tblFind.Edit;
  96. //            tblFind.FindField(tblFind.FieldDefs.Items[I].Name).FocusControl;
  97. //            tblFind.FieldByName(tblFind.FieldDefs.Items[I].Name).FocusControl;
  98.             Break;
  99.           end;
  100.         end;
  101.       end;
  102.       if FFound then
  103.         Break;
  104.       tblFind.Next;
  105.     end
  106.   else
  107.     while not tblFind.BOF do begin
  108.       for I := 0 to tblFind.FieldDefs.Count - 1 do begin
  109.         Application.ProcessMessages;
  110.         if FAbortProcess then begin
  111.           tblFind.EnableControls;
  112.           FAbortProcess := False;
  113.           Abort;
  114.         end;
  115.         if (tblFind.FindField(tblFind.FieldDefs.Items[I].Name) <> nil) then begin
  116.           SearchField := tblFind.FindField(tblFind.FieldDefs.Items[I].Name);
  117.           if (Pos(UpperCase(sFindText),UpperCase(SearchField.AsString)) > 0) then begin
  118.             FFound := True;
  119.             if FAutoEdit then
  120.               tblFind.Edit;
  121. //            tblFind.FindField(tblFind.FieldDefs.Items[I].Name).FocusControl;
  122. //            tblFind.FieldByName(tblFind.FieldDefs.Items[I].Name).FocusControl;
  123.             Break;
  124.           end;
  125.         end;
  126.       end;
  127.       if FFound then
  128.         Break;
  129.       tblFind.Prior;
  130.     end;
  131.   tblFind.EnableControls;
  132.   if tblFind.EOF then begin
  133.     FFound := False;
  134.     tblFind.First;
  135.     if (MessageDlg('Text '+'"'+FindText+'"'+' Not Found, '#13+
  136.        'would you like to continue from first record',mtInformation,[mbYes,mbNo],0) = mrYes) then
  137.       Find(Sender);
  138.   end;
  139. end;
  140.  
  141. procedure TFindDlg.Replace(Sender : TObject);
  142. begin
  143.   {}
  144. end;
  145.  
  146. destructor TFindDlg.Destroy;
  147. begin
  148.   inherited Destroy;
  149. end;
  150.  
  151. procedure Register;
  152. begin
  153.   RegisterComponents('Delphi 3.0 Components', [TFindDlg]);
  154. end;
  155.  
  156. end.
  157.