home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap09 / howto10 / delphi10 / cciccinf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-27  |  11.6 KB  |  349 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.     Outline1: TOutline;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  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.  
  51. implementation
  52.  
  53. uses CCICCFrm;
  54.  
  55. {$R *.DFM}
  56. function inet_addr( IPAddressName : PChar ) :
  57.           Unsigned_Long_Integer; far; external 'WINSOCK';
  58. function inet_ntoa( Socket_IP_Address:  Internet_Address ) :
  59.           PChar; far; external 'WINSOCK';
  60. function gethostbyname( TheName : PChar ) :
  61.           PHost_Entry; far; external 'WINSOCK';
  62.  
  63. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  64. var TempSocket : TCCSocket; { Used for IP Address info }
  65.     DataBuffer : array[ 0 .. 256 ] of char;
  66. begin
  67.   case Tag of
  68.     1 : begin  { Get IP Address Mode }
  69.           { Create the dummy socket }
  70.           TempSocket := TCCSocket.Create( Self );
  71.           TempSocket.Parent := Self;
  72.           { Use it to get the info }
  73.           with TempSocket do
  74.           begin
  75.             { Move the IP address into the data buffer }
  76.             StrPCopy( DataBuffer , Edit1.Text );
  77.             { Turn it into a real IP address in binary form }
  78.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  79.              inet_addr( DataBuffer );
  80.             { If not found then do remote lookup }
  81.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  82.             begin
  83.               { Call blocking function on IP name }
  84.               Socket_Host_Entry := gethostbyname( DataBuffer );
  85.               { If still no good then error out and exit }
  86.               if Socket_Host_Entry = nil then
  87.               begin
  88.                 Edit2.Text := 'Could Not Convert Host Name';
  89.                 Edit3.Text := '';
  90.               end
  91.               else
  92.               begin
  93.                 { Otherwise get the address }
  94.                 Socket_IP_Address.Socket_Address :=
  95.                  Socket_Host_Entry^.Host_Address^^;
  96.                 Edit2.Text :=
  97.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  98.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  99.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  100.                  '.' + IntToStr(
  101.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  102.                 Edit3.Text :=
  103.                  IntToStr( Socket_IP_Address.Socket_Address.
  104.                             Full_Internet_Address );
  105.               end;
  106.             end;
  107.           end;
  108.           { Free the dummy socket }
  109.           TempSocket.Free;
  110.         end;
  111.     2 : begin { Anonymous login punch }
  112.           Edit3.Text := 'anonymous';
  113.           CurrentRealPWString := CurrentPassWordString;
  114.           case PasswordControlVector of
  115.             1 : Edit4.Text := CurrentPassWordString;
  116.             2 : Edit4.Text := '**********';
  117.           end;
  118.         end;
  119.   end;
  120. end;
  121.  
  122. procedure TCCICInfoDlg.ListBox2Click(Sender: TObject);
  123. begin
  124.   { Use Tag vector to find out how to interpret a click }
  125.   case Tag of
  126.     2 : begin
  127.           { If nothing in list box then exit }
  128.           if ListBox2.ItemIndex = -1 then exit;
  129.           { Use the data in the Working FTP Site List TList }
  130.           with PConnectionsRecord(
  131.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  132.           begin
  133.               Edit1.Text := CProfile;
  134.               Edit2.Text := CIPAddress;
  135.               Edit3.Text := CUserName;
  136.               CurrentRealPWString := CPassword;
  137.               case PasswordControlVector of
  138.                 1 : Edit4.Text := CPassword;
  139.                 2 : Edit4.Text := '**********';
  140.               end;
  141.               Edit5.Text := CStartDir;
  142.           end;
  143.         end;
  144.   end;
  145. end;
  146.  
  147. { This procedure saves the newly modified list of stuff to its base }
  148. procedure TCCICInfoDlg.BitBtn1Click(Sender: TObject);
  149. var Counter_1  : Integer;            { Loop counter        }
  150.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  151. begin
  152.   { Use the tag vector to find out what to do }
  153.   case Tag of
  154.     2 : begin { Do FTP Site List }
  155.           { dispose the old FTP site list's pointers }
  156.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  157.           begin
  158.             Dispose( PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] ));
  159.           end;
  160.           { Clear the lists }
  161.           TheFTPSiteList.Clear;
  162.           CCInetCCForm.ComboBox1.Clear;
  163.           { Add the new info }
  164.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  165.           begin
  166.             { Create a new pointer }
  167.             New( ThePointer );
  168.             { Move the data into it }
  169.             ThePointer^ :=
  170.              PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] )^;
  171.             { Add the item }
  172.             TheFTPSiteList.Add( ThePointer );
  173.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  174.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  175.           end;
  176.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  177.         end;
  178.   end;
  179.   { Leave }
  180.   Close;
  181. end;
  182.  
  183. { This method cancels any changes made from entries in current setup & exits}
  184. procedure TCCICInfoDlg.BitBtn2Click(Sender: TObject);
  185. var Counter_1  : Integer;            { Loop counter        }
  186.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  187. begin
  188.   { Use Tag vector do decide what to reset }
  189.   case Tag of
  190.     2 : begin { Reset FTP Site list }
  191.           { Dispose of all the old pointers }
  192.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  193.           begin
  194.             Dispose( PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] ));
  195.           end;
  196.           { Clear the working list }
  197.           TheWorkingFTPSL.Clear;
  198.           { Clear the listbox }
  199.           ListBox2.Clear;
  200.           { Then rebuild the working list and display listbox }
  201.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  202.           begin
  203.             { Create the record }
  204.             New( ThePointer );
  205.             { Move data in }
  206.             ThePointer^ :=
  207.              PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  208.             { Add the pointer to the list }
  209.             TheWorkingFTPSL.Add( ThePointer );
  210.             { Add the profile name to the list }
  211.             ListBox2.Items.Add( PConnectionsRecord(
  212.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  213.           end;
  214.         end;
  215.   end;
  216.   { Leave }
  217.   Close;
  218. end;
  219.  
  220. procedure TCCICInfoDlg.Edit4Exit(Sender: TObject);
  221. begin
  222.   { Use tag vector to determine action }
  223.   case Tag of
  224.     2 : begin
  225.           { If Edit4 is modified then mangle pw }
  226.           if Edit4.Modified then
  227.           begin
  228.             { Save pw in either case, but mangle if masked }
  229.             case PasswordControlVector of
  230.               1 : CurrentRealPWString := Edit4.Text;
  231.               2 : begin
  232.                     CurrentRealPWString := Edit4.Text;
  233.                     Edit4.Text := '***********';
  234.                   end;
  235.             end;
  236.           end;
  237.         end;
  238.   end;
  239. end;
  240.  
  241. { Add button; do various add actions }
  242. procedure TCCICInfoDlg.Button2Click(Sender: TObject);
  243. var ThePointer : PConnectionsRecord; { PCR Pointer }
  244. begin
  245.   { Tag vector control as usual }
  246.   case Tag of
  247.     2 : begin { add new FTP site list entry }
  248.           { Creat new PCR pointer }
  249.           New( ThePointer );
  250.           { Add in the data from the text fields }
  251.           with ThePointer^ do
  252.           begin
  253.             CProfile   := Edit1.Text;
  254.             CIPAddress := Edit2.Text;;
  255.             CUserName  := Edit3.Text;
  256.             { Put in the real pw string }
  257.             CPassword  := CurrentRealPWString;
  258.             CStartDir  := Edit5.Text;
  259.           end;
  260.           { Add pointer to working list }
  261.           TheWorkingFTPSL.Add( ThePointer );
  262.           { Add it to the listbox }
  263.           ListBox2.Items.Add( ThePointer^.CProfile );
  264.           { And set the pointer to it }
  265.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  266.         end;
  267.   end;
  268. end;
  269.  
  270. { This is the modify button }
  271. procedure TCCICInfoDlg.Button3Click(Sender: TObject);
  272. begin
  273.   { Use Tag vector as usual }
  274.   case Tag of
  275.     2 : begin
  276.           { if nothing to modify the exit }
  277.           if ListBox2.ItemIndex = -1 then exit;
  278.           { get record of current listbox pointer & put in data }
  279.           with PConnectionsRecord(
  280.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  281.           begin
  282.             CProfile   := Edit1.Text;
  283.             CIPAddress := Edit2.Text;;
  284.             CUserName  := Edit3.Text;
  285.             { Put in the real pw string }
  286.             CPassword  := CurrentRealPWString;
  287.             CStartDir  := Edit5.Text;
  288.           end;
  289.           { Make sure the display matches the edit control }
  290.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  291.         end;
  292.   end;
  293. end;
  294.  
  295. { This is the delete button }
  296. procedure TCCICInfoDlg.Button4Click(Sender: TObject);
  297. var MessageString : String; { String holder }
  298. begin
  299.   { Use tag control vector }
  300.   case Tag of
  301.     2 : begin
  302.           { If nothing to delete then leave }
  303.           if Listbox2.Itemindex = -1 then exit;
  304.           { Set up display }
  305.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  306.           { Display message box and get result }
  307.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  308.            = mrYes then
  309.           begin
  310.             { if ok delete then remove item from working sl }
  311.             TheWorkingFTPSL.Delete( ListBox2.ItemIndex );
  312.             { delete from listbox }
  313.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  314.             { If nothing left set itemindex and clear edits }
  315.             if ListBox2.Items.Count = 0 then
  316.             begin
  317.               ListBox2.ItemIndex := -1;
  318.               Edit1.Text := '';
  319.               Edit2.Text := '';
  320.               Edit3.Text := '';
  321.               Edit4.Text := '';
  322.               Edit5.Text := '';
  323.             end
  324.             else
  325.             begin
  326.               { Reset listbox pointer }
  327.               ListBox2.ItemIndex  := 0;
  328.               { and reset display to new item }
  329.               with PConnectionsRecord(
  330.                TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  331.               begin
  332.                 Edit1.Text := CProfile;
  333.                 Edit2.Text := CIPAddress;
  334.                 Edit3.Text := CUserName;
  335.                 CurrentRealPWString := CPassword;
  336.                 case PasswordControlVector of
  337.                   1 : Edit4.Text := CPassword;
  338.                   2 : Edit4.Text := '**********';
  339.                 end;
  340.                 Edit5.Text := CStartDir;
  341.               end;
  342.             end;
  343.           end;
  344.         end;
  345.   end;
  346. end;
  347.  
  348. end.
  349.