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

  1. {*****************************************************************************
  2.  *
  3.  *  FMAddress.pas - Address Book Form  (20-August-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 FMAddress;
  34.  
  35. interface
  36.  
  37. uses
  38.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  39.   Menus, ComCtrls, FMEditAdr, ExtCtrls, Buttons, ParserSup, PXStuff,
  40.   ImgList, StdCtrls, ComboBoxEx, FMSelBook, EnhListView, ExtListView, Registry,
  41.   FMSearch, LangSup, IniFiles;
  42.  
  43. type
  44.   TAddressForm = class(TForm)
  45.     MainMenu1: TMainMenu;
  46.     Address1: TMenuItem;
  47.     New1: TMenuItem;
  48.     Delete1: TMenuItem;
  49.     N1: TMenuItem;
  50.     Edit1: TMenuItem;
  51.     PopupMenu1: TPopupMenu;
  52.     NewAddress1: TMenuItem;
  53.     DeleteAddress1: TMenuItem;
  54.     N2: TMenuItem;
  55.     EditAddress1: TMenuItem;
  56.     Panel1: TPanel;
  57.     Bevel1: TBevel;
  58.     StatusBar1: TStatusBar;
  59.     N3: TMenuItem;
  60.     MailtoAddresses1: TMenuItem;
  61.     Close1: TMenuItem;
  62.     SpeedButton1: TSpeedButton;
  63.     SpeedButton2: TSpeedButton;
  64.     SpeedButton3: TSpeedButton;
  65.     SpeedButton4: TSpeedButton;
  66.     SpeedButton5: TSpeedButton;
  67.     N4: TMenuItem;
  68.     MailtoAddresses2: TMenuItem;
  69.     File1: TMenuItem;
  70.     ImageList1: TImageList;
  71.     Search1: TMenuItem;
  72.     N5: TMenuItem;
  73.     SpeedButton6: TSpeedButton;
  74.     Book1: TMenuItem;
  75.     New2: TMenuItem;
  76.     Delete2: TMenuItem;
  77.     ComboBox1: TComboBoxEx;
  78.     SelectAllAddresses1: TMenuItem;
  79.     SelectAll1: TMenuItem;
  80.     N7: TMenuItem;
  81.     Rename1: TMenuItem;
  82.     SpeedButton10: TSpeedButton;
  83.     Movetoanotherbook1: TMenuItem;
  84.     ListView1: TExtListView;
  85.     N6: TMenuItem;
  86.     Image1: TImage;
  87.     Bevel2: TBevel;
  88.     Bevel3: TBevel;
  89.     Bevel4: TBevel;
  90.     Bevel5: TBevel;
  91.     Help1: TMenuItem;
  92.     Contents1: TMenuItem;
  93.     procedure New1Click(Sender: TObject);
  94.     procedure FormShow(Sender: TObject);
  95.     procedure Edit1Click(Sender: TObject);
  96.     procedure Delete1Click(Sender: TObject);
  97.     procedure Close1Click(Sender: TObject);
  98.     procedure ListView1KeyDown(Sender: TObject; var Key: Word;
  99.       Shift: TShiftState);
  100.     procedure MailtoAddresses1Click(Sender: TObject);
  101.     procedure FormCreate(Sender: TObject);
  102.     procedure Search1Click(Sender: TObject);
  103.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  104.     procedure New2Click(Sender: TObject);
  105.     procedure Delete2Click(Sender: TObject);
  106.     procedure ComboBox1Change(Sender: TObject);
  107.     procedure SelectAllAddresses1Click(Sender: TObject);
  108.     procedure Rename1Click(Sender: TObject);
  109.     procedure Movetoanotherbook1Click(Sender: TObject);
  110.     procedure PopupMenu1Popup(Sender: TObject);
  111.     procedure FormDestroy(Sender: TObject);
  112.     procedure ListView1DrawHeader(Control: TWinControl;
  113.       var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
  114.       Selected: Boolean; var DefaultDrawing: Boolean);
  115.     procedure ListView1MouseUp(Sender: TObject; Button: TMouseButton;
  116.       Shift: TShiftState; X, Y: Integer);
  117.     procedure Contents1Click(Sender: TObject);
  118.   private
  119.     { Private declarations }
  120.     MailOK: Boolean;
  121.     Filename: String;
  122.     function ToAddressFormat(I1: Integer; S1, S2, S3, S4, S5: String): String;
  123.     procedure FromAddressFormat(S: String; var I1: Integer; var S1, S2, S3, S4, S5: String);
  124.     procedure LoadAddressBook;
  125.     procedure SaveAddressBook;
  126.   public
  127.     { Public declarations }
  128.     function GetSelAddresses: String;
  129.     function SetAddress(S: String): Boolean;
  130.     procedure SetMenusEnable;
  131.     procedure SetStatusBar;
  132.   end;
  133.  
  134. var
  135.   AddressForm: TAddressForm;
  136.  
  137. implementation
  138.  
  139. {$R *.DFM}
  140.  
  141. uses
  142.   Main;
  143.  
  144. var
  145.   F: Text;
  146.  
  147. procedure TAddressForm.SetStatusBar;
  148. begin
  149.   StatusBar1.Panels[0].Text := Format(MainForm.ListBox1.Items[38], [IntToStr(ListView1.Items.Count), IntToStr(ListView1.SelCount)]);
  150. end;
  151.  
  152. function TAddressForm.ToAddressFormat(I1: Integer; S1, S2, S3, S4, S5: String): String;
  153. begin
  154.   Result := IntToStr(I1)+','+S1+','+S2+','+S3+','+S4+','+S5;
  155. end;
  156.  
  157. procedure TAddressForm.FromAddressFormat(S: String; var I1: Integer; var S1, S2, S3, S4, S5: String);
  158. var
  159.   I: Integer;
  160. begin
  161.   I := Pos(',', S);
  162.   I1 := 0;
  163.   try
  164.     I1 := StrToInt(Copy(S, 1, I-1));
  165.   except end;
  166.   Delete(S, 1, I);
  167.  
  168.   I := Pos(',', S);
  169.   S1 := Copy(S, 1, I-1);
  170.   Delete(S, 1, I);
  171.  
  172.   I := Pos(',', S);
  173.   S2 := Copy(S, 1, I-1);
  174.   Delete(S, 1, I);
  175.  
  176.   I := Pos(',', S);
  177.   S3 := Copy(S, 1, I-1);
  178.   Delete(S, 1, I);
  179.  
  180.   I := Pos(',', S);
  181.   S4 := Copy(S, 1, I-1);
  182.   Delete(S, 1, I);
  183.  
  184.   S5 := S;
  185. end;
  186.  
  187. function TAddressForm.SetAddress(S: String): Boolean;
  188. begin
  189.   if Combobox1.Items.Count = 0 then begin
  190.     MessageDlg(MainForm.ListBox1.Items[39], mtwarning, [mbOK], 0);
  191.     Result := False;
  192.     Exit;
  193.   end;
  194.   EditAdrForm := TEditAdrForm.Create(Self);
  195.   EditAdrForm.CheckUnique := True;
  196.   EditAdrForm.Caption := MainForm.ListBox1.Items[40];
  197.   EditAdrForm.ComboboxEx1.ItemIndex := 0;
  198.   EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
  199.   EditAdrForm.Edit5.Text := ExtractEMailName(S);
  200.   EditAdrForm.Edit2.Text := ExtractEMailAddress(S);
  201.   if EditAdrForm.ShowModal = mrOK then begin
  202.     SaveAddressBook;
  203.     AssignFile(F, EditAdrForm.Combobox1.Values[EditAdrForm.Combobox1.ItemIndex]);
  204.     Append(F);
  205.     S := ToAddressFormat(EditAdrForm.ComboboxEx1.ItemIndex, EditAdrForm.Edit5.Text, EditAdrForm.Edit1.Text, EditAdrForm.Edit2.Text, EditAdrForm.Edit3.Text, EditAdrForm.Edit4.Text);
  206.     WriteLn(F, S);
  207.     CloseFile(F);
  208.     LoadAddressBook;
  209.   end;
  210.   EditAdrForm.Free;
  211.   Result := True;
  212. end;
  213.  
  214. function TAddressForm.GetSelAddresses: String;
  215. var
  216.   SL: TStringList;
  217.   I: Integer;
  218. begin
  219.   SL := TStringList.Create;
  220.   for I := 0 to ListView1.Items.Count-1 do
  221.     if ListView1.Items[I].Selected then
  222.       SL.Add(ListView1.Items[I].SubItems[0]+' <'+ListView1.Items[I].SubItems[2]+'>');
  223.   Result := StringListToCommataString(SL, False);
  224.   SL.Free;
  225. end;
  226.  
  227. procedure TAddressForm.LoadAddressBook;
  228. var
  229.   Item: TListItem;
  230.   S, S1, S2, S3, S4, S5: String;
  231.   I1: Integer;
  232. begin
  233.   if Filename = '' then Exit;
  234.   if FileExists(Filename) = False then Exit;
  235.   ListView1.BeginUpdate;
  236.   ListView1.Items.Clear;
  237.   AssignFile(F, Filename);
  238.   Reset(F);
  239.   ReadLn(F, S);
  240.   ReadLn(F, S); //two empty lines
  241.   while not EoF(F) do begin
  242.     ReadLn(F, S);
  243.     FromAddressFormat(S, I1, S1, S2, S3, S4, S5);
  244.     Item := ListView1.Items.Add;
  245.     Item.ImageIndex := I1;
  246.     Item.SubItems.Add(S1);
  247.     Item.SubItems.Add(S2);
  248.     Item.SubItems.Add(S3);
  249.     Item.SubItems.Add(S4);
  250.     Item.SubItems.Add(S5);
  251.   end;
  252.   CloseFile(F);
  253.   ListView1.Resort;
  254.   ListView1.EndUpdate;
  255. end;
  256.  
  257. procedure TAddressForm.SaveAddressBook;
  258. var
  259.   I: Integer;
  260.   S: String;
  261. begin
  262.   if Filename = '' then Exit;
  263.   AssignFile(F, Filename);
  264.   Rewrite(F);
  265.   WriteLn(F, 'Phoenix Mail - Copyright 1998-99 Michael Haller');
  266.   WriteLn(F, 'Type,Description,Name,E-Mail,Phone,Address');
  267.   for I := 0 to ListView1.Items.Count-1 do begin
  268.     S := ToAddressFormat(ListView1.Items[I].ImageIndex, ListView1.Items[I].SubItems[0], ListView1.Items[I].SubItems[1], ListView1.Items[I].SubItems[2], ListView1.Items[I].SubItems[3], ListView1.Items[I].SubItems[4]);
  269.     WriteLn(F, S);
  270.   end;
  271.   CloseFile(F);
  272. end;
  273.  
  274. procedure TAddressForm.SetMenusEnable;
  275. begin
  276.   if Filename = '' then begin
  277.     ListView1.Items.Clear;
  278.     ListView1.Enabled := False;
  279.     Delete2.Enabled := False;
  280.     Address1.Enabled := False;
  281.     Rename1.Enabled := False;
  282.     SpeedButton1.Enabled := False;
  283.     SpeedButton6.Enabled := False;
  284.   end else begin
  285.     Rename1.Enabled := True;
  286.     ListView1.Enabled := True;
  287.     Delete2.Enabled := True;
  288.     Address1.Enabled := True;
  289.     SpeedButton1.Enabled := True;
  290.     SpeedButton6.Enabled := True;
  291.   end;
  292.   if (ListView1.Selected <> nil) and (Filename <> '') then begin
  293.     Delete1.Enabled := True;
  294.     Edit1.Enabled := True;
  295.     DeleteAddress1.Enabled := True;
  296.     MailToAddresses1.Enabled := True;
  297.     MailToAddresses2.Enabled := True;
  298.     SpeedButton4.Enabled := True;
  299.     SpeedButton5.Enabled := True;
  300.     if Combobox1.Items.Count > 1 then begin
  301.       SpeedButton10.Enabled := True;
  302.       Movetoanotherbook1.Enabled := True;
  303.     end;
  304.   end else begin
  305.     Delete1.Enabled := False;
  306.     Edit1.Enabled := False;
  307.     DeleteAddress1.Enabled := False;
  308.     MailToAddresses1.Enabled := False;
  309.     MailToAddresses2.Enabled := False;
  310.     SpeedButton4.Enabled := False;
  311.     SpeedButton5.Enabled := False;
  312.     Movetoanotherbook1.Enabled := False;
  313.     SpeedButton10.Enabled := False;
  314.   end;
  315.   if (Filename <> '') and (ListView1.SelCount = 1) and (ListView1.Selected <> nil) then begin
  316.     SpeedButton3.Enabled := True;
  317.     EditAddress1.Enabled := True;
  318.   end else begin
  319.     SpeedButton3.Enabled := False;
  320.     EditAddress1.Enabled := False;
  321.   end;
  322.   SetStatusBar;
  323. end;
  324.  
  325. procedure TAddressForm.New1Click(Sender: TObject);
  326. var
  327.   S: String;
  328. begin
  329.   EditAdrForm := TEditAdrForm.Create(Self);
  330.   EditAdrForm.CheckUnique := True;
  331.   EditAdrForm.Caption := MainForm.ListBox1.Items[40];
  332.   EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
  333.   EditAdrForm.ComboBoxEx1.ItemIndex := 0;
  334.   if EditAdrForm.ShowModal = mrOK then begin
  335.     SaveAddressBook;
  336.     AssignFile(F, EditAdrForm.Combobox1.Values[EditAdrForm.Combobox1.ItemIndex]);
  337.     Append(F);
  338.     S := ToAddressFormat(EditAdrForm.ComboBoxEx1.ItemIndex, EditAdrForm.Edit5.Text, EditAdrForm.Edit1.Text, EditAdrForm.Edit2.Text, EditAdrForm.Edit3.Text, EditAdrForm.Edit4.Text);
  339.     WriteLn(F, S);
  340.     CloseFile(F);
  341.     LoadAddressBook;
  342.   end;
  343.   EditAdrForm.Free;
  344.   ListView1.Resort;
  345. end;
  346.  
  347. procedure TAddressForm.FormShow(Sender: TObject);
  348. var
  349.   I: Integer;
  350. begin
  351.   ListView1.Selected := nil;
  352.   for I := 0 to ListView1.Items.Count-1 do ListView1.Items[I].Selected := False;
  353.   SetMenusEnable;
  354.   MailOK := False;
  355.   if bFlatButtons then begin
  356.     Set3DButtons(True, Self);
  357.     Bevel2.Visible := True; Bevel3.Visible := True;
  358.     Bevel4.Visible := True; Bevel5.Visible := True;
  359.   end else begin
  360.     Set3DButtons(False, Self);
  361.     Bevel2.Visible := False; Bevel3.Visible := False;
  362.     Bevel4.Visible := False; Bevel5.Visible := False;
  363.   end;
  364. end;
  365.  
  366. procedure TAddressForm.Edit1Click(Sender: TObject);
  367. var
  368.   Item: TListItem;
  369. begin
  370.   Item := ListView1.Selected;
  371.   if Item = nil then Exit;
  372.   EditAdrForm := TEditAdrForm.Create(Self);
  373.   EditAdrForm.CheckUnique := False;
  374.   EditAdrForm.ComboBox1.Enabled := False;
  375.   EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
  376.   EditAdrForm.Label5.Enabled := False;
  377.   EditAdrForm.ComboboxEx1.ItemIndex := Item.ImageIndex;
  378.   EditAdrForm.Edit5.Text := Item.SubItems[0];
  379.   EditAdrForm.Edit1.Text := Item.SubItems[1];
  380.   EditAdrForm.Edit2.Text := Item.SubItems[2];
  381.   EditAdrForm.Edit3.Text := Item.SubItems[3];
  382.   EditAdrForm.Edit4.Text := Item.SubItems[4];
  383.   if EditAdrForm.ShowModal = mrOK then begin
  384.     Item.ImageIndex := EditAdrForm.ComboboxEx1.ItemIndex;
  385.     Item.SubItems[0] := EditAdrForm.Edit5.Text;
  386.     Item.SubItems[1] := EditAdrForm.Edit1.Text;
  387.     Item.SubItems[2] := EditAdrForm.Edit2.Text;
  388.     Item.SubItems[3] := EditAdrForm.Edit3.Text;
  389.     Item.SubItems[4] := EditAdrForm.Edit4.Text;
  390.   end;
  391.   EditAdrForm.Free;
  392. end;
  393.  
  394. procedure TAddressForm.Delete1Click(Sender: TObject);
  395. var
  396.   I: Integer;
  397. label Jump1;
  398. begin
  399. Jump1:
  400.   for I := 0 to ListView1.Items.Count-1 do
  401.     if ListView1.Items[I].Selected then
  402.       if MessageDlg(Format(MainForm.ListBox1.Items[41], [ListView1.Items[I].SubItems[0]]), mtWarning, [mbYes, mbNo], 0) = mrYes then begin
  403.         ListView1.Items[I].Delete;
  404.         GoTo Jump1;
  405.       end;
  406. end;
  407.  
  408. procedure TAddressForm.Close1Click(Sender: TObject);
  409. begin
  410.   Close;
  411. end;
  412.  
  413. procedure TAddressForm.ListView1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  414. begin
  415.   if Ord(Key) = 46 then Delete1Click(Self);
  416. end;
  417.  
  418. procedure TAddressForm.MailtoAddresses1Click(Sender: TObject);
  419. begin
  420.   if ListView1.Selected = nil then Exit;
  421.   MailOK := True;
  422.   Close;
  423. end;
  424.  
  425. procedure TAddressForm.FormCreate(Sender: TObject);
  426. var
  427.   Found: Integer;
  428.   SearchRec: TSearchRec;
  429.   IniFile: TIniFile;
  430. begin
  431.   ImageList1.ResourceLoad(rtBitmap, 'PX502', clFuchsia);
  432.   if bOfficeFonts then Font.Name := sOfficeFontName;
  433.   if bFlatButtons = False then begin
  434.     Set3DButtons(False, Self);
  435.     Bevel2.Visible := False;
  436.     Bevel3.Visible := False;
  437.     Bevel4.Visible := False;
  438.     Bevel5.Visible := False;
  439.   end;
  440.   Filename := '';
  441.   Found := FindFirst(sAddressBookFolder+'*.csv', faAnyFile, SearchRec);
  442.   while Found = 0 do begin
  443.     SetFileAttr(sAddressBookFolder+SearchRec.Name, False, True, False, False);
  444.     ComboBox1.Values.Add(sAddressBookFolder+SearchRec.Name);
  445.     Delete(SearchRec.Name, Length(SearchRec.Name)-3, 4);
  446.     Combobox1.Items.Add(SearchRec.Name);
  447.     ComboBox1.ImgIndexes.Add('5');
  448.     Found := FindNext(SearchRec);
  449.     Combobox1.ItemIndex := 0;
  450.     Filename := Combobox1.Values[0];
  451.   end;
  452.   FindClose(SearchRec);
  453.   // Form Position
  454.   IniFile := TIniFile.Create(sSettingsFile);
  455.   case IniFile.ReadInteger('Position', 'AddressState', 1) of
  456.     0, 1: begin
  457.       WindowState := wsNormal;
  458.       Width := IniFile.ReadInteger('Position', 'AddressWidth', Width);
  459.       Height := IniFile.ReadInteger('Position', 'AddressHeight', Height);
  460.       Top := IniFile.ReadInteger('Position', 'AddressTop', Top);
  461.       Left := IniFile.ReadInteger('Position', 'AddressLeft', Left);
  462.     end;
  463.     2: WindowState := wsMaximized;
  464.   end;
  465.   // ListView Order/Position
  466.   if MainForm.CheckBox1.Checked then begin
  467.     ListView1.AutoSortStyle := assSmart;
  468.   end;
  469.   ListView1.ReadSettingsFromIniFile('AddressList', IniFile);
  470.   LoadAddressBook;
  471.   SetMenusEnable;
  472.   AttachLanguageToForm(Self);
  473.   IniFile.Free;
  474. end;
  475.  
  476. procedure TAddressForm.Search1Click(Sender: TObject);
  477. begin
  478.   SearchForm := TSearchForm.Create(Self);
  479.   SearchForm.Method := 1;
  480.   SearchForm.ShowModal;
  481.   SearchForm.Free;
  482. end;
  483.  
  484. procedure TAddressForm.FormClose(Sender: TObject; var Action: TCloseAction);
  485. begin
  486.   SaveAddressBook;
  487.   if MailOK then ModalResult := mrOK else ModalResult := mrCancel;
  488. end;
  489.  
  490. procedure TAddressForm.New2Click(Sender: TObject);
  491. var
  492.   S: String;
  493.   I: Integer;
  494. begin
  495.   if InputQuery(MainForm.ListBox1.Items[42], MainForm.ListBox1.Items[43], S) then begin
  496.     for I := 1 to Length(S) do
  497.       if S[I] in ['\','/','<','>',':','?','*','"','|',#19] then begin
  498.         MessageDlg(MainForm.ListBox1.Items[44], mtError, [mbOK], 0);
  499.         Exit;
  500.       end;
  501.     SaveAddressBook;
  502.     Filename := sAddressBookFolder+S+'.csv';
  503.     ComboBox1.ImgIndexes.Add('5');
  504.     ComboBox1.Items.Add(S);
  505.     ComboBox1.Values.Add(sAddressBookFolder+S+'.csv');
  506.     ComboBox1.ItemIndex := Combobox1.Items.Count-1;
  507.     AssignFile(F, Filename);
  508.     Rewrite(F);
  509.     CloseFile(F);
  510.     LoadAddressBook;
  511.     SetMenusEnable;
  512.   end;
  513. end;
  514.  
  515. procedure TAddressForm.Delete2Click(Sender: TObject);
  516. var
  517.   I: Integer;
  518. begin
  519.   if Filename = '' then Exit;
  520.   if MessageDlg(Format(MainForm.ListBox1.Items[45], [Combobox1.Items[ComboBox1.ItemIndex]]), mtWarning, [mbYes,mbNo],0) = mrYes then
  521.     if MessageDlg(Format(MainForm.ListBox1.Items[46], [Combobox1.Items[ComboBox1.ItemIndex]]), mtWarning, [mbYes,mbNo],0) = mrYes then begin
  522.       DeleteFile(Filename);
  523.       I := Combobox1.ItemIndex;
  524.       Filename := '';
  525.       ComboBox1.Items.Delete(I);
  526.       ComboBox1.Values.Delete(I);
  527.       ComboBox1.ImgIndexes.Delete(I);
  528.       if Combobox1.Items.Count = 0 then begin
  529.         Filename := '';
  530.       end else begin
  531.         ComboBox1.ItemIndex := 0;
  532.         Filename := ComboBox1.Values[ComboBox1.ItemIndex];
  533.       end;
  534.       Combobox1.Invalidate;
  535.       LoadAddressBook;
  536.       SetMenusEnable;
  537.     end;
  538. end;
  539.  
  540. procedure TAddressForm.ComboBox1Change(Sender: TObject);
  541. begin
  542.   if ComboBox1.ItemIndex = -1 then begin
  543.     Filename := '';
  544.     Exit;
  545.   end;
  546.   SaveAddressBook;
  547.   Filename := ComboBox1.Values[ComboBox1.ItemIndex];
  548.   LoadAddressBook;
  549.   SetMenusEnable;
  550. end;
  551.  
  552. procedure TAddressForm.SelectAllAddresses1Click(Sender: TObject);
  553. var
  554.   I: Integer;
  555. begin
  556.   for I := 0 to ListView1.Items.Count-1 do
  557.     ListView1.Items[I].Selected := True;
  558.   SetMenusEnable;
  559. end;
  560.  
  561. procedure TAddressForm.Rename1Click(Sender: TObject);
  562. var
  563.   S: String;
  564.   I, E: Integer;
  565. begin
  566.   I := ComboBox1.ItemIndex;
  567.   if I = -1 then Exit;
  568.   SaveAddressBook;
  569.   S := ComboBox1.Items[I];
  570.   if InputQuery(MainForm.ListBox1.Items[47], MainForm.ListBox1.Items[43], S) then begin
  571.     for E := 1 to Length(S) do
  572.       if S[E] in ['\','/','<','>',':','?','*','"','|',#19] then begin
  573.         MessageDlg(MainForm.ListBox1.Items[44], mtError, [mbOK], 0);
  574.         Exit;
  575.       end;
  576.     RenameFile(Filename, sAddressBookFolder+S+'.csv');
  577.     Filename := sAddressBookFolder+S+'.csv';
  578.     ComboBox1.Items[I] := S;
  579.     ComboBox1.Values[I] := sAddressBookFolder+S+'.csv';
  580.     ComboBox1.ItemIndex := I;
  581.     ComboBox1.Invalidate;
  582.   end;
  583. end;
  584.  
  585. procedure TAddressForm.Movetoanotherbook1Click(Sender: TObject);
  586. var
  587.   S: String;
  588.   I, E: Integer;
  589. begin
  590.   SelBookForm := TSelBookForm.Create(Self);
  591.   if SelBookForm.ShowModal = mrOK then begin
  592.     S := SelBookForm.Combobox1.Values[SelBookForm.ComboBox1.ItemIndex];
  593.     AssignFile(F, S);
  594.     Append(F);
  595.     E := ListView1.Items.Count-1;
  596.     I := 0;
  597.     while I <= E do begin
  598.       if ListView1.Items[I].Selected then begin
  599.         S := ToAddressFormat(ListView1.Items[I].ImageIndex, ListView1.Items[I].SubItems[0], ListView1.Items[I].SubItems[1], ListView1.Items[I].SubItems[2], ListView1.Items[I].SubItems[3], ListView1.Items[I].SubItems[4]);
  600.         WriteLn(F, S);
  601.         ListView1.Items[I].Delete;
  602.         Dec(E); Dec(I);
  603.       end;
  604.       Inc(I);
  605.     end;
  606.     CloseFile(F);
  607.   end;
  608.   SelBookForm.Free;
  609. end;
  610.  
  611. procedure TAddressForm.PopupMenu1Popup(Sender: TObject);
  612. begin
  613.   SetMenusEnable;
  614. end;
  615.  
  616. procedure TAddressForm.FormDestroy(Sender: TObject);
  617. var
  618.   IniFile: TIniFile;
  619. begin
  620.   IniFile := TIniFile.Create(sSettingsFile);
  621.   // ListView
  622.   ListView1.WriteSettingsToIniFile('AddressList', IniFile);
  623.   // Form Position
  624.   if WindowState = wsNormal then begin
  625.     IniFile.WriteInteger('Position', 'AddressState', 1);
  626.     IniFile.WriteInteger('Position', 'AddressWidth', Width);
  627.     IniFile.WriteInteger('Position', 'AddressHeight', Height);
  628.     IniFile.WriteInteger('Position', 'AddressTop', Top);
  629.     IniFile.WriteInteger('Position', 'AddressLeft', Left);
  630.   end;
  631.   if WindowState = wsMaximized then IniFile.WriteInteger('Position', 'AddressState', 2);
  632.   IniFile.Free;
  633. end;
  634.  
  635. procedure TAddressForm.ListView1DrawHeader(Control: TWinControl;
  636.   var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
  637.   Selected: Boolean; var DefaultDrawing: Boolean);
  638. begin
  639.   if Index = 0 then begin
  640.     DefaultDrawing := False;
  641.     ACanvas.BrushCopy(Rect(ARect.Left+2, ARect.Top, ARect.Left+18, ARect.Top+16), Image1.Picture.Bitmap, Rect(0, 0, 16, 16), clFuchsia);
  642.   end else
  643.     DefaultDrawing := True;
  644. end;
  645.  
  646. procedure TAddressForm.ListView1MouseUp(Sender: TObject;
  647.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  648. begin
  649.   SetMenusEnable;
  650.   SetStatusBar;
  651. end;
  652.  
  653. procedure TAddressForm.Contents1Click(Sender: TObject);
  654. begin
  655.   Application.HelpContext(9);
  656. end;
  657.  
  658. end.
  659.