clientFrm.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
源码类别:

Delphi/CppBuilder

开发平台:

Delphi

  1. unit clientFrm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, MConnect, ObjBrkr, DB, DBClient, SConnect, ExtCtrls, DBCtrls,
  6.   Grids, DBGrids, StdCtrls, Buttons;
  7. type
  8.   TfrmClient = class(TForm)
  9.     SocketConnection1: TSocketConnection;
  10.     ClientDataSet1: TClientDataSet;
  11.     DataSource1: TDataSource;
  12.     SimpleObjectBroker1: TSimpleObjectBroker;
  13.     Panel1: TPanel;
  14.     Panel2: TPanel;
  15.     DBGrid1: TDBGrid;
  16.     DBNavigator1: TDBNavigator;
  17.     edtAppServerName: TEdit;
  18.     edtAppServerTime: TEdit;
  19.     btnGetServerInfo: TBitBtn;
  20.     btnClear: TBitBtn;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     procedure btnGetServerInfoClick(Sender: TObject);
  24.     procedure btnClearClick(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.   public
  28.     { Public declarations }
  29.   end;
  30. var
  31.   frmClient: TfrmClient;
  32. implementation
  33. {$R *.dfm}
  34. procedure TfrmClient.btnGetServerInfoClick(Sender: TObject);
  35. var
  36.   vServerName: Variant;
  37.   vServerTime: Variant;
  38. begin
  39.   try
  40.     //调用服务器端提供的GetServerName方法和GetServerTime方法
  41.     socketConnection1.AppServer.GetServerName(vServerName);
  42.     socketConnection1.AppServer.GetServerTime(vServerTime);
  43.     edtAppServerName.Text := vServerName;
  44.     edtAppServerTime.Text := vServerTime;
  45.   //调用失败,就用SimpleObjectBroker1组件,去连接别的服务器,以获得服务
  46.   except
  47.     on exception do
  48.     begin
  49.       SimpleObjectBroker1.SetConnectStatus(SocketConnection1.Host, false);
  50.       SocketConnection1.Connected := False;
  51.       SocketConnection1.Host := simpleObjectBroker1.GetComputerForProgID('Server.CorrectServer');
  52.       socketConnection1.Connected := True;
  53.       btnGetServerInfoClick(Sender);
  54.     end;
  55.   end;
  56. end;
  57. procedure TfrmClient.btnClearClick(Sender: TObject);
  58. begin
  59.   edtAppServerName.Text :='';
  60.   edtAppServerTime.Text :='';
  61. end;
  62. end.