home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedftp.exe / Samples / Delphi / FTPClient / unConnectInfo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-05  |  5.1 KB  |  139 lines

  1. { --------------------------------------------------------------- }
  2. { Xceed FTP Library - client sample                               }
  3. { Copyright (c) 2000 Xceed Software Inc.                          }
  4. {                                                                 }
  5. { [frmConnect.pas]                                                }
  6. {                                                                 }
  7. { This form contains code for the "Connection Information"        }
  8. { dialog box.                                                     }
  9. {                                                                 }
  10. { This file is part of the Xceed FTP Library Sample applications. }
  11. { The source code in this file is only intended as a supplement   }
  12. { to Xceed FTP Library's documentation, and is provided "as is",  }
  13. { without warranty of any kind, either expressed or implied.      }
  14. { --------------------------------------------------------------- }
  15.  
  16. unit unConnectInfo;
  17.  
  18. interface
  19.  
  20. uses
  21.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22.   StdCtrls;
  23.  
  24. type
  25.   TfrmConnect = class(TForm)
  26.     edtHostAddress : TEdit;
  27.     edtUserName    : TEdit;
  28.     edtPassword    : TEdit;
  29.     edtPort        : TEdit;
  30.     lblHostAddress : TLabel;
  31.     lblUserName    : TLabel;
  32.     lblPassword    : TLabel;
  33.     lblPort        : TLabel;
  34.     grpLoginType   : TGroupBox;
  35.     optAnonymous   : TRadioButton;
  36.     optNormal      : TRadioButton;
  37.     btConnect      : TButton;
  38.     btCancel       : TButton;
  39.  
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure optNormalClick(Sender: TObject);
  42.     procedure optAnonymousClick(Sender: TObject);
  43.     procedure btCancelClick(Sender: TObject);
  44.     procedure btConnectClick(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.   public
  48.     { Set to true or false depending on if the cancel button was clicked }
  49.     m_bCancelled           : boolean;
  50.  
  51.     function GetConnectInfo(var sHostAddress : string; var nPort : integer;
  52.                             var sUserName : string; var sPassword : string) : boolean;
  53.   end;
  54.  
  55. var
  56.   frmConnect   : TfrmConnect;
  57. implementation
  58.  
  59. {$R *.DFM}
  60. { ------------------------------------------------------------- }
  61. procedure TfrmConnect.FormCreate(Sender: TObject);
  62. begin
  63.   m_bCancelled := false;          { Initialize to false (means user clicked Connect button }
  64.   optAnonymous.Checked := true;   { By default, we want anonymous to be selected }
  65. end;
  66.  
  67. { ------------------------------------------------------------- }
  68. { If the "normal" option is selected, we will enable the        }
  69. { username and password edit boxes.                             }
  70. { ------------------------------------------------------------- }
  71. procedure TfrmConnect.optNormalClick(Sender: TObject);
  72. begin
  73.   edtUserName.Enabled := true;  { Enable the username edit box }
  74.   edtPassword.Enabled := true;  { Enable the password edit box }
  75.  
  76.   edtUserName.Color := $80000009;
  77.   edtPassword.Color := $80000009;
  78. end;
  79.  
  80. { ------------------------------------------------------------- }
  81. { If the "anonymous" option is selected, we will disable the    }
  82. { username and password edit boxes.                             }
  83. { ------------------------------------------------------------- }
  84. procedure TfrmConnect.optAnonymousClick(Sender: TObject);
  85. begin
  86.   edtUserName.Enabled := false; { Disable the username edit box }
  87.   edtPassword.Enabled := false; { Disable the password edit box }
  88.  
  89.   edtUserName.Color := $8000000F;
  90.   edtPassword.Color := $8000000F;
  91. end;
  92.  
  93. { ------------------------------------------------------------- }
  94. procedure TfrmConnect.btCancelClick(Sender: TObject);
  95. begin
  96.   m_bCancelled := true; { Set to true if cancel button was clicked }
  97.   Self.Close;           { Close the "Connection Information" dialog form }
  98. end;
  99.  
  100. { ------------------------------------------------------------- }
  101. { The following procedure is called by the DoConnect procedure  }
  102. { of our main form. It retreives the information entered in     }
  103. { frmConnect and sends it back to the DoConnect procedure.      }
  104. { ------------------------------------------------------------- }
  105. function TfrmConnect.GetConnectInfo(var sHostAddress : string;
  106.                                     var nPort : integer; var sUserName : string;
  107.                                     var sPassword : string) : boolean;
  108. begin
  109.   m_bCancelled := false;
  110.   Self.ShowModal;
  111.  
  112.   if not m_bCancelled then
  113.   begin
  114.     sHostAddress := edtHostAddress.Text;  { Set the host address }
  115.     nPort := StrToInt(edtPort.Text);      { Set port. Default is 21 }
  116.  
  117.     if optAnonymous.Checked then  { anonymous }
  118.     begin
  119.       sUserName := 'anonymous';
  120.       sPassword := 'guest';
  121.     end
  122.     else
  123.     begin
  124.       sUserName := edtUserName.Text;  { Set the username }
  125.       sPassword := edtPassword.Text;  { Set the password }
  126.     end;
  127.   end;
  128.  
  129.   GetConnectInfo := not m_bCancelled;
  130. end;
  131.  
  132. { ------------------------------------------------------------- }
  133. procedure TfrmConnect.btConnectClick(Sender: TObject);
  134. begin
  135.   m_bCancelled := false;
  136.   Self.Close;
  137. end;
  138. end.
  139.