home *** CD-ROM | disk | FTP | other *** search
/ Freelog 11 / Freelog011.iso / BestOf / PhoenixMail / Source / phoenix / FMSearch.pas < prev    next >
Pascal/Delphi Source File  |  1999-02-05  |  5KB  |  169 lines

  1. {*****************************************************************************
  2.  *
  3.  *  FMSearch.pas - Search Mails and Addresses  (12-September-1998)
  4.  *
  5.  *  Copyright (c) 1998-99 Michael Haller
  6.  *
  7.  *  Author:     Michael Haller
  8.  *  E-mail:     michael@discountdrive.com
  9.  *  Homepage:   http://www.discountdrive.com/sunrise
  10.  *
  11.  *  This program is free software; you can redistribute it and/or
  12.  *  modify it under the terms of the GNU General Public License
  13.  *  as published by the Free Software Foundation;
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  *
  24.  *----------------------------------------------------------------------------
  25.  *
  26.  *  Revision history:
  27.  *
  28.  *     DATE     REV                 DESCRIPTION
  29.  *  ----------- --- ----------------------------------------------------------
  30.  *
  31.  *****************************************************************************}
  32.  
  33. unit FMSearch;
  34.  
  35. interface
  36.  
  37. uses
  38.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  39.   StdCtrls, ComCtrls, PXStuff, LangSup;
  40.  
  41. type
  42.   TSearchForm = class(TForm)
  43.     Animate1: TAnimate;
  44.     Label1: TLabel;
  45.     Edit1: TEdit;
  46.     Button1: TButton;
  47.     Button2: TButton;
  48.     Label2: TLabel;
  49.     Label3: TLabel;
  50.     Label4: TLabel;
  51.     Label5: TLabel;
  52.     procedure Button1Click(Sender: TObject);
  53.     procedure FormCreate(Sender: TObject);
  54.     procedure Edit1Change(Sender: TObject);
  55.     procedure FormShow(Sender: TObject);
  56.   private
  57.     { Private declarations }
  58.   public
  59.     { Public declarations }
  60.     SearchIndex, Method: Integer;
  61.   end;
  62.  
  63. var
  64.   SearchForm: TSearchForm;
  65.  
  66. implementation
  67.  
  68. {$R *.DFM}
  69.  
  70. uses
  71.   Main, FMAddress;
  72.  
  73. procedure TSearchForm.Button1Click(Sender: TObject);
  74. var
  75.   I, E, Y: Integer;
  76.   F: Boolean;
  77.   S: String;
  78.   P: TPoint;
  79.   Item: TListItem;
  80. begin
  81.   Button1.Caption := Label4.Caption;
  82.   F := False;
  83.  
  84.   if Method = 0 then begin//Mainform
  85.     if SaveMessage then MainForm.DoSaveMessage;
  86.     for I := 0 to MainForm.ListView1.Items.Count-1 do
  87.       MainForm.ListView1.Items[I].Selected := False;
  88.     MainForm.ListView1MouseUp(Self, mbLeft, [ssLeft], 0, 0);
  89.     for I := SearchIndex to MainForm.ListView1.Items.Count-1 do begin
  90.       S := '';
  91.       for E := 0 to 3 do S := S + MainForm.ListView1.Items[I].SubItems[E];
  92.       S := LowerCase(S);
  93.       if Pos(LowerCase(Edit1.Text), S) <> 0 then begin
  94.         MainForm.ListView1.Selected := MainForm.ListView1.Items[I];
  95.         MainForm.ListView1MouseUp(Self, mbLeft, [ssLeft], 0, 0);
  96.         SearchIndex := I+1;
  97.         F := True;
  98.         Item := MainForm.ListView1.GetItemAt(2, 20);
  99.         if Assigned(Item) then begin
  100.           P := MainForm.ListView1.Selected.GetPosition;
  101.           Y := P.Y;
  102.           P := Item.GetPosition;
  103.           MainForm.ListView1.Scroll(0, -(P.Y - Y));
  104.         end;
  105.         Break;
  106.       end;
  107.     end;
  108.   end;
  109.  
  110.   if Method = 1 then begin //AddressForm
  111.     for I := 0 to AddressForm.ListView1.Items.Count-1 do
  112.       AddressForm.ListView1.Items[I].Selected := False;
  113.     AddressForm.SetMenusEnable;
  114.     AddressForm.SetStatusBar;
  115.     for I := SearchIndex to AddressForm.ListView1.Items.Count-1 do begin
  116.       S := AddressForm.ListView1.Items[I].SubItems[0]+AddressForm.ListView1.Items[I].SubItems[1]+
  117.            AddressForm.ListView1.Items[I].SubItems[2]+AddressForm.ListView1.Items[I].SubItems[3]+
  118.            AddressForm.ListView1.Items[I].SubItems[4];
  119.       S := LowerCase(S);
  120.       if Pos(LowerCase(Edit1.Text), S) <> 0 then begin
  121.         AddressForm.ListView1.Selected := AddressForm.ListView1.Items[I];
  122.         AddressForm.SetMenusEnable;
  123.         AddressForm.SetStatusBar;
  124.         SearchIndex := I+1;
  125.         F := True;
  126.         Item := AddressForm.ListView1.GetItemAt(2, 20);
  127.         if Assigned(Item) then begin
  128.           P := AddressForm.ListView1.Selected.GetPosition;
  129.           Y := P.Y;
  130.           P := Item.GetPosition;
  131.           AddressForm.ListView1.Scroll(0, -(P.Y - Y));
  132.         end;
  133.         Break;
  134.       end;
  135.     end;
  136.   end;
  137.  
  138.   if F = False then
  139.     MessageDlg(Format(Mainform.ListBox1.Items[75]+'  ', [Edit1.Text]), mtInformation, [mbOK], 0);
  140. end;
  141.  
  142. procedure TSearchForm.FormCreate(Sender: TObject);
  143. begin
  144.   AttachLanguageToForm(Self);
  145.   SearchIndex := 0;
  146.   Button1.Caption := Label5.Caption;
  147.   if bOfficeFonts then Font.Name := sOfficeFontName;
  148. end;
  149.  
  150. procedure TSearchForm.Edit1Change(Sender: TObject);
  151. begin
  152.   SearchIndex := 0;
  153.   Button1.Caption := Label5.Caption;
  154.   if Edit1.Text = '' then
  155.     Button1.Enabled := False
  156.   else
  157.     Button1.Enabled := True;
  158. end;
  159.  
  160. procedure TSearchForm.FormShow(Sender: TObject);
  161. begin
  162.   if Method = 1 then begin
  163.     Label2.Visible := False;
  164.     Caption := Label3.Caption;
  165.   end;
  166. end;
  167.  
  168. end.
  169.