home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap10 / howto01 / cciccinf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  16.5 KB  |  481 lines

  1. unit Cciccinf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, Outline, CCWSock;
  8.  
  9. type
  10.   TCCICInfoDlg = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     Panel4: TPanel;
  15.     ListBox2: TListBox;
  16.     Panel2: TPanel;
  17.     Edit1: TEdit;
  18.     Panel3: TPanel;
  19.     Edit2: TEdit;
  20.     Panel5: TPanel;
  21.     Edit3: TEdit;
  22.     Panel8: TPanel;
  23.     Edit4: TEdit;
  24.     Panel9: TPanel;
  25.     Edit5: TEdit;
  26.     Panel6: TPanel;
  27.     Label1: TLabel;
  28.     Label2: TLabel;
  29.     Button1: TButton;
  30.     Button2: TButton;
  31.     Button3: TButton;
  32.     Button4: TButton;
  33.     ListBox1: TListBox;
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ListBox2Click(Sender: TObject);
  36.     procedure BitBtn1Click(Sender: TObject);
  37.     procedure BitBtn2Click(Sender: TObject);
  38.     procedure Edit4Exit(Sender: TObject);
  39.     procedure Button2Click(Sender: TObject);
  40.     procedure Button3Click(Sender: TObject);
  41.     procedure Button4Click(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. var
  49.   CCICInfoDlg: TCCICInfoDlg;
  50. const
  51.   LBClickVector : Integer = 0;
  52.   ActiveMailbox : Integer = 0;
  53.  
  54. implementation
  55.  
  56. uses CCICCFrm;
  57.  
  58. {$R *.DFM}
  59. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  60. var TempSocket : TCCSocket; { Used for IP Address info }
  61.     DataBuffer : array[ 0 .. 256 ] of char;
  62. begin
  63.   case Tag of
  64.     1 : begin  { Get IP Address Mode }
  65.           { Create the dummy socket }
  66.           TempSocket := TCCSocket.Create( Self );
  67.           TempSocket.Parent := Self;
  68.           { Use it to get the info }
  69.           with TempSocket do
  70.           begin
  71.             { Move the IP address into the data buffer }
  72.             StrPCopy( DataBuffer , Edit1.Text );
  73.             { Turn it into a real IP address in binary form }
  74.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  75.              inet_addr( DataBuffer );
  76.             { If not found then do remote lookup }
  77.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  78.             begin
  79.               { Call blocking function on IP name }
  80.               Socket_Host_Entry := gethostbyname( DataBuffer );
  81.               { If still no good then error out and exit }
  82.               if Socket_Host_Entry = nil then
  83.               begin
  84.                 Edit2.Text := 'Could Not Convert Host Name';
  85.                 Edit3.Text := '';
  86.               end
  87.               else
  88.               begin
  89.                 { Otherwise get the address }
  90.                 Socket_IP_Address.Socket_Address :=
  91.                  Socket_Host_Entry^.Host_Address^^;
  92.                 Edit2.Text :=
  93.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  94.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  95.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  96.                  '.' + IntToStr(
  97.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  98.                 Edit3.Text :=
  99.                  IntToStr( Socket_IP_Address.Socket_Address.
  100.                             Full_Internet_Address );
  101.               end;
  102.             end;
  103.           end;
  104.           { Free the dummy socket }
  105.           TempSocket.Free;
  106.         end;
  107.     2 : begin { Anonymous login punch }
  108.           Edit3.Text := 'anonymous';
  109.           CurrentRealPWString := CurrentPassWordString;
  110.           case PasswordControlVector of
  111.             1 : Edit4.Text := CurrentPassWordString;
  112.             2 : Edit4.Text := '**********';
  113.           end;
  114.         end;
  115.   end;
  116. end;
  117.  
  118. procedure TCCICInfoDlg.ListBox2Click(Sender: TObject);
  119. var TheWorkingList  : TList;
  120.     Counter_1       : Integer;
  121.     Finished        : Boolean;
  122. begin
  123.   { Use Tag vector to find out how to interpret a click }
  124.   case Tag of
  125.     2 : begin
  126.           { If nothing in list box then exit }
  127.           if ListBox2.ItemIndex = -1 then exit;
  128.           { Use the data in the Working FTP Site List TList }
  129.           with PConnectionsRecord(
  130.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  131.           begin
  132.               Edit1.Text := CProfile;
  133.               Edit2.Text := CIPAddress;
  134.               Edit3.Text := CUserName;
  135.               CurrentRealPWString := CPassword;
  136.               case PasswordControlVector of
  137.                 1 : Edit4.Text := CPassword;
  138.                 2 : Edit4.Text := '**********';
  139.               end;
  140.               Edit5.Text := CStartDir;
  141.           end;
  142.         end;
  143.     4 : begin
  144.           { If nothing in list box then exit }
  145.           if ListBox2.ItemIndex = -1 then exit;
  146.           { Use the data in the Working FTP Site List TList }
  147.           with PConnectionsRecord(
  148.            TheWorkingNSSL.Items[ ListBox2.ItemIndex ] )^ do
  149.           begin
  150.               Edit1.Text := CProfile;
  151.               Edit2.Text := CIPAddress;
  152.           end;
  153.         end;
  154.   end;
  155. end;
  156.  
  157. { This procedure saves the newly modified list of stuff to its base }
  158. procedure TCCICInfoDlg.BitBtn1Click(Sender: TObject);
  159. var Counter_1  : Integer;            { Loop counter        }
  160.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  161. begin
  162.   { Use the tag vector to find out what to do }
  163.   case Tag of
  164.     2 : begin { Do FTP Site List }
  165.           { dispose the old FTP site list's pointers }
  166.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  167.           begin
  168.             Dispose( PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] ));
  169.           end;
  170.           { Clear the lists }
  171.           TheFTPSiteList.Clear;
  172.           CCInetCCForm.ComboBox1.Clear;
  173.           { Add the new info }
  174.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  175.           begin
  176.             { Create a new pointer }
  177.             New( ThePointer );
  178.             { Move the data into it }
  179.             ThePointer^ :=
  180.              PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] )^;
  181.             { Add the item }
  182.             TheFTPSiteList.Add( ThePointer );
  183.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  184.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  185.           end;
  186.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  187.         end;
  188.     4 : begin { Do NNTP Site List }
  189.           { dispose the old FTP site list's pointers }
  190.           for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  191.           begin
  192.             Dispose( PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] ));
  193.           end;
  194.           { Clear the lists }
  195.           TheNewsServerList.Clear;
  196.           CCInetCCForm.ComboBox1.Clear;
  197.           { Add the new info }
  198.           for Counter_1 := 0 to TheWorkingNSSL.Count - 1 do
  199.           begin
  200.             { Create a new pointer }
  201.             New( ThePointer );
  202.             { Move the data into it }
  203.             ThePointer^ :=
  204.              PConnectionsRecord( TheWorkingNSSL.Items[ Counter_1 ] )^;
  205.             { Add the item }
  206.             TheNewsServerList.Add( ThePointer );
  207.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  208.              TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  209.           end;
  210.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  211.         end;
  212.   end;
  213.   { Leave }
  214.   Close;
  215. end;
  216.  
  217. { This method cancels any changes made from entries in current setup & exits}
  218. procedure TCCICInfoDlg.BitBtn2Click(Sender: TObject);
  219. var Counter_1  : Integer;            { Loop counter        }
  220.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  221. begin
  222.   { Use Tag vector do decide what to reset }
  223.   case Tag of
  224.     2 : begin { Reset FTP Site list }
  225.           { Dispose of all the old pointers }
  226.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  227.           begin
  228.             Dispose( PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] ));
  229.           end;
  230.           { Clear the working list }
  231.           TheWorkingFTPSL.Clear;
  232.           { Clear the listbox }
  233.           ListBox2.Clear;
  234.           { Then rebuild the working list and display listbox }
  235.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  236.           begin
  237.             { Create the record }
  238.             New( ThePointer );
  239.             { Move data in }
  240.             ThePointer^ :=
  241.              PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  242.             { Add the pointer to the list }
  243.             TheWorkingFTPSL.Add( ThePointer );
  244.             { Add the profile name to the list }
  245.             ListBox2.Items.Add( PConnectionsRecord(
  246.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  247.           end;
  248.         end;
  249.     4 : begin { Reset NNTP Site list }
  250.           { Dispose of all the old pointers }
  251.           for Counter_1 := 0 to TheWorkingNSSL.Count - 1 do
  252.           begin
  253.             Dispose( PConnectionsRecord( TheWorkingNSSL.Items[ Counter_1 ] ));
  254.           end;
  255.           { Clear the working list }
  256.           TheWorkingNSSL.Clear;
  257.           { Clear the listbox }
  258.           ListBox2.Clear;
  259.           { Then rebuild the working list and display listbox }
  260.           for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  261.           begin
  262.             { Create the record }
  263.             New( ThePointer );
  264.             { Move data in }
  265.             ThePointer^ :=
  266.              PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] )^;
  267.             { Add the pointer to the list }
  268.             TheWorkingNSSL.Add( ThePointer );
  269.             { Add the profile name to the list }
  270.             ListBox2.Items.Add( PConnectionsRecord(
  271.              TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  272.           end;
  273.         end;
  274.   end;
  275.   { Leave }
  276.   Close;
  277. end;
  278.  
  279. procedure TCCICInfoDlg.Edit4Exit(Sender: TObject);
  280. begin
  281.   { Use tag vector to determine action }
  282.   case Tag of
  283.     2 : begin
  284.           { If Edit4 is modified then mangle pw }
  285.           if Edit4.Modified then
  286.           begin
  287.             { Save pw in either case, but mangle if masked }
  288.             case PasswordControlVector of
  289.               1 : CurrentRealPWString := Edit4.Text;
  290.               2 : begin
  291.                     CurrentRealPWString := Edit4.Text;
  292.                     Edit4.Text := '***********';
  293.                   end;
  294.             end;
  295.           end;
  296.         end;
  297.   end;
  298. end;
  299.  
  300. { Add button; do various add actions }
  301. procedure TCCICInfoDlg.Button2Click(Sender: TObject);
  302. var ThePointer  : PConnectionsRecord; { PCR Pointer }
  303.     TempList    : TList;
  304. begin
  305.   { Tag vector control as usual }
  306.   case Tag of
  307.     2 : begin { add new FTP site list entry }
  308.           { Creat new PCR pointer }
  309.           New( ThePointer );
  310.           { Add in the data from the text fields }
  311.           with ThePointer^ do
  312.           begin
  313.             CProfile   := Edit1.Text;
  314.             CIPAddress := Edit2.Text;;
  315.             CUserName  := Edit3.Text;
  316.             { Put in the real pw string }
  317.             CPassword  := CurrentRealPWString;
  318.             CStartDir  := Edit5.Text;
  319.           end;
  320.           { Add pointer to working list }
  321.           TheWorkingFTPSL.Add( ThePointer );
  322.           { Add it to the listbox }
  323.           ListBox2.Items.Add( ThePointer^.CProfile );
  324.           { And set the pointer to it }
  325.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  326.         end;
  327.     4 : begin { add new NNTP site list entry }
  328.           { Creat new PCR pointer }
  329.           New( ThePointer );
  330.           { Add in the data from the text fields }
  331.           with ThePointer^ do
  332.           begin
  333.             CProfile   := Edit1.Text;
  334.             CIPAddress := Edit2.Text;;
  335.             CUserName  := '';
  336.             CPassword  := '';
  337.             CStartDir  := '';
  338.           end;
  339.           { Add pointer to working list }
  340.           TheWorkingNSSL.Add( ThePointer );
  341.           { Add it to the listbox }
  342.           ListBox2.Items.Add( ThePointer^.CProfile );
  343.           { And set the pointer to it }
  344.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  345.         end;
  346.   end;
  347. end;
  348.  
  349. { This is the modify button }
  350. procedure TCCICInfoDlg.Button3Click(Sender: TObject);
  351. begin
  352.   { Use Tag vector as usual }
  353.   case Tag of
  354.     2 : begin
  355.           { if nothing to modify the exit }
  356.           if ListBox2.ItemIndex = -1 then exit;
  357.           { get record of current listbox pointer & put in data }
  358.           with PConnectionsRecord(
  359.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  360.           begin
  361.             CProfile   := Edit1.Text;
  362.             CIPAddress := Edit2.Text;;
  363.             CUserName  := Edit3.Text;
  364.             { Put in the real pw string }
  365.             CPassword  := CurrentRealPWString;
  366.             CStartDir  := Edit5.Text;
  367.           end;
  368.           { Make sure the display matches the edit control }
  369.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  370.         end;
  371.     4 : begin
  372.           { if nothing to modify the exit }
  373.           if ListBox2.ItemIndex = -1 then exit;
  374.           { get record of current listbox pointer & put in data }
  375.           with PConnectionsRecord(
  376.            TheWorkingNSSL.Items[ ListBox2.ItemIndex ] )^ do
  377.           begin
  378.             CProfile   := Edit1.Text;
  379.             CIPAddress := Edit2.Text;
  380.             CUserName  := '';
  381.             CPassword  := '';
  382.             CStartDir  := '';
  383.           end;
  384.           { Make sure the display matches the edit control }
  385.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  386.         end;
  387.   end;
  388. end;
  389.  
  390. { This is the delete button }
  391. procedure TCCICInfoDlg.Button4Click(Sender: TObject);
  392. var MessageString : String; { String holder }
  393. begin
  394.   { Use tag control vector }
  395.   case Tag of
  396.     2 : begin
  397.           { If nothing to delete then leave }
  398.           if Listbox2.Itemindex = -1 then exit;
  399.           { Set up display }
  400.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  401.           { Display message box and get result }
  402.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  403.            = mrYes then
  404.           begin
  405.             { if ok delete then remove item from working sl }
  406.             TheWorkingFTPSL.Delete( ListBox2.ItemIndex );
  407.             { delete from listbox }
  408.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  409.             { If nothing left set itemindex and clear edits }
  410.             if ListBox2.Items.Count = 0 then
  411.             begin
  412.               ListBox2.ItemIndex := -1;
  413.               Edit1.Text := '';
  414.               Edit2.Text := '';
  415.               Edit3.Text := '';
  416.               Edit4.Text := '';
  417.               Edit5.Text := '';
  418.             end
  419.             else
  420.             begin
  421.               { Reset listbox pointer }
  422.               ListBox2.ItemIndex  := 0;
  423.               { and reset display to new item }
  424.               with PConnectionsRecord(
  425.                TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  426.               begin
  427.                 Edit1.Text := CProfile;
  428.                 Edit2.Text := CIPAddress;
  429.                 Edit3.Text := CUserName;
  430.                 CurrentRealPWString := CPassword;
  431.                 case PasswordControlVector of
  432.                   1 : Edit4.Text := CPassword;
  433.                   2 : Edit4.Text := '**********';
  434.                 end;
  435.                 Edit5.Text := CStartDir;
  436.               end;
  437.             end;
  438.           end;
  439.         end;
  440.     4 : begin
  441.           { If nothing to delete then leave }
  442.           if Listbox2.Itemindex = -1 then exit;
  443.           { Set up display }
  444.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  445.           { Display message box and get result }
  446.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  447.            = mrYes then
  448.           begin
  449.             { if ok delete then remove item from working sl }
  450.             TheWorkingNSSL.Delete( ListBox2.ItemIndex );
  451.             { delete from listbox }
  452.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  453.             { If nothing left set itemindex and clear edits }
  454.             if ListBox2.Items.Count = 0 then
  455.             begin
  456.               ListBox2.ItemIndex := -1;
  457.               Edit1.Text := '';
  458.               Edit2.Text := '';
  459.               Edit3.Text := '';
  460.               Edit4.Text := '';
  461.               Edit5.Text := '';
  462.             end
  463.             else
  464.             begin
  465.               { Reset listbox pointer }
  466.               ListBox2.ItemIndex  := 0;
  467.               { and reset display to new item }
  468.               with PConnectionsRecord(
  469.                TheWorkingNSSL.Items[ ListBox2.ItemIndex ] )^ do
  470.               begin
  471.                 Edit1.Text := CProfile;
  472.                 Edit2.Text := CIPAddress;
  473.               end;
  474.             end;
  475.           end;
  476.         end;
  477.   end;
  478. end;
  479.  
  480. end.
  481.