home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / DELPHIX.ZIP / Samples / Network / Chat2 / Config.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-06  |  4.5 KB  |  175 lines

  1. unit Config;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls, DXPlay, DirectX;
  8.  
  9. type
  10.   TConfigForm = class(TForm)
  11.     ProviderList: TComboBox;
  12.     Label1: TLabel;
  13.     ProviderSetting: TNotebook;
  14.     SessionListBox: TListBox;
  15.     Label2: TLabel;
  16.     JoinButton: TButton;
  17.     HostButton: TButton;
  18.     SessionNameEdit: TEdit;
  19.     PlayerNameEdit: TEdit;
  20.     Label3: TLabel;
  21.     Label4: TLabel;
  22.     TCPIPHostName: TEdit;
  23.     Label5: TLabel;
  24.     Label6: TLabel;
  25.     ModemPhoneNumber: TEdit;
  26.     Label7: TLabel;
  27.     ModemComboBox: TComboBox;
  28.     TCPIPConnectButton: TButton;
  29.     ModemConnectButton: TButton;
  30.     OtherConnectButton: TButton;
  31.     procedure FormShow(Sender: TObject);
  32.     procedure ProviderListChange(Sender: TObject);
  33.     procedure TCPIPConnectButtonClick(Sender: TObject);
  34.     procedure OtherConnectButtonClick(Sender: TObject);
  35.     procedure JoinButtonClick(Sender: TObject);
  36.     procedure HostButtonClick(Sender: TObject);
  37.     procedure SessionListBoxClick(Sender: TObject);
  38.     procedure ModemConnectButtonClick(Sender: TObject);
  39.   private
  40.     procedure Connect;
  41.   public
  42.     DXPlay: TDXPlay;
  43.   end;
  44.  
  45. var
  46.   ConfigForm: TConfigForm;
  47.  
  48. implementation
  49.  
  50. {$R *.DFM}
  51.  
  52. procedure TConfigForm.FormShow(Sender: TObject);
  53. begin
  54.   ProviderList.Items := DXPlay.Providers;
  55.   ProviderList.ItemIndex := 0;
  56.   ProviderListChange(nil);
  57. end;
  58.  
  59. procedure TConfigForm.ProviderListChange(Sender: TObject);
  60. begin
  61.   SessionListBox.Items.Clear;
  62.  
  63.   DXPlay.ProviderName := '';
  64.   JoinButton.Enabled := False;
  65.   HostButton.Enabled := False;
  66.  
  67.   SessionListBox.Enabled := False;
  68.   SessionListBox.Color := clBtnFace;
  69.   SessionNameEdit.Enabled := False;
  70.   SessionNameEdit.Color := clBtnFace;
  71.   PlayerNameEdit.Enabled := False;
  72.   PlayerNameEdit.Color := clBtnFace;
  73.  
  74.   if CompareMem(PGUID(ProviderList.Items.Objects[ProviderList.ItemIndex]), @DPSPGUID_TCPIP, SizeOf(TGUID)) then
  75.   begin
  76.     {  TCP/IP  }
  77.     ProviderSetting.ActivePage := 'ProviderSettingTCPIP';
  78.   end else
  79.   if CompareMem(PGUID(ProviderList.Items.Objects[ProviderList.ItemIndex]), @DPSPGUID_MODEM, SizeOf(TGUID)) then
  80.   begin
  81.     {  Modem  }
  82.     ProviderSetting.ActivePage := 'ProviderSettingModem';
  83.     if ModemComboBox.Items.Count=0 then
  84.     begin
  85.       Screen.Cursor := crHourGlass;
  86.       try
  87.         ModemComboBox.Items := DXPlay.ModemSetting.ModemNames;
  88.         ModemComboBox.ItemIndex := 0;
  89.       finally
  90.         Screen.Cursor := crDefault;
  91.       end;
  92.     end;
  93.   end else
  94.   begin
  95.     {  Other  }
  96.     ProviderSetting.ActivePage := 'Default';
  97.   end;
  98. end;
  99.  
  100. procedure TConfigForm.Connect;
  101. begin
  102.   Screen.Cursor := crHourGlass;
  103.   try
  104.     DXPlay.GetSessions;
  105.     SessionListBox.Items := DXPlay.Sessions;
  106.   finally
  107.     Screen.Cursor := crDefault;
  108.   end;
  109.  
  110.   JoinButton.Enabled := SessionListBox.Items.Count>0;
  111.   HostButton.Enabled := True;
  112.   if JoinButton.Enabled then
  113.   begin
  114.     SessionListBox.Enabled := True;
  115.     SessionListBox.Color := clWhite;
  116.   end;
  117.   SessionNameEdit.Enabled := True;
  118.   SessionNameEdit.Color := clWhite;
  119.   PlayerNameEdit.Enabled := True;
  120.   PlayerNameEdit.Color := clWhite;
  121. end;
  122.  
  123. procedure TConfigForm.TCPIPConnectButtonClick(Sender: TObject);
  124. begin
  125.   SessionListBox.Items.Clear;
  126.  
  127.   DXPlay.TCPIPSetting.HostName := TCPIPHostName.Text;
  128.   DXPlay.TCPIPSetting.Enabled := True;
  129.   DXPlay.ProviderName := ProviderList.Items[ProviderList.ItemIndex];
  130.  
  131.   Connect;
  132. end;
  133.  
  134. procedure TConfigForm.ModemConnectButtonClick(Sender: TObject);
  135. begin
  136.   SessionListBox.Items.Clear;
  137.  
  138.   DXPlay.ModemSetting.PhoneNumber := ModemPhoneNumber.Text;
  139.   DXPlay.ModemSetting.ModemName := ModemComboBox.Items[ModemComboBox.ItemIndex];
  140.   DXPlay.ModemSetting.Enabled := True;
  141.   DXPlay.ProviderName := ProviderList.Items[ProviderList.ItemIndex];
  142.  
  143.   Connect;
  144. end;
  145.  
  146. procedure TConfigForm.OtherConnectButtonClick(Sender: TObject);
  147. begin
  148.   SessionListBox.Items.Clear;
  149.  
  150.   DXPlay.ProviderName := ProviderList.Items[ProviderList.ItemIndex];
  151.  
  152.   Connect;
  153. end;
  154.  
  155. procedure TConfigForm.JoinButtonClick(Sender: TObject);
  156. begin
  157.   DXPlay.Open2(False, SessionNameEdit.Text, PlayerNameEdit.Text);
  158.   Tag := 1;
  159.   Close;
  160. end;
  161.  
  162. procedure TConfigForm.HostButtonClick(Sender: TObject);
  163. begin
  164.   DXPlay.Open2(True, SessionNameEdit.Text, PlayerNameEdit.Text);
  165.   Tag := 1;
  166.   Close;
  167. end;
  168.  
  169. procedure TConfigForm.SessionListBoxClick(Sender: TObject);
  170. begin
  171.   SessionNameEdit.Text := SessionListBox.Items[SessionListBox.ItemIndex];
  172. end;
  173.  
  174. end.
  175.