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