home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Runimage / Delphi50 / Source / Vcl / MIDASCON.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  3.8 KB  |  148 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {       Connection compatibility classes                }
  6. {                                                       }
  7. {       Copyright (c) 1997,99 Inprise Corporation       }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit MidasCon;
  12.  
  13. interface
  14.  
  15. uses
  16.   Classes, MConnect, SConnect;
  17.  
  18. type
  19.  
  20. { TRemoteServer }
  21. { Provided for compatiblity.  Switch to using the TDCOMConnection }
  22.  
  23.   TRemoteServer = class(TDCOMConnection)
  24.   end;
  25.  
  26. { TMidasConnection }
  27. { Provided for compatiblity.
  28.   For ConnectType ctDCOM, switch to TDCOMConnection,
  29.   for ctSockets, switch to TSocketConnection,
  30.   for ctOLEnterprise, switch to TOLEnterpriseConnection. }
  31.  
  32.   TConnectType = (ctDCOM, ctSockets, ctOLEnterprise);
  33.  
  34.   TMidasConnection = class(TDCOMConnection)
  35.   private
  36.     FSubConnection: TDispatchConnection;
  37.     FConnectType: TConnectType;
  38.     FServerPort: Integer;
  39.     FUseBroker: Boolean;
  40.   protected
  41.     procedure SetConnectType(Value: TConnectType); virtual;
  42.     procedure SetUseBroker(Value: Boolean); virtual;
  43.     procedure DoConnect; override;
  44.     procedure DoDisconnect; override;
  45.   public
  46.     constructor Create(AOwner: TComponent); override;
  47.   published
  48.     property ConnectType: TConnectType read FConnectType write SetConnectType;
  49.     property ServerPort: Integer read FServerPort write FServerPort default 211;
  50.     property UseBroker: Boolean read FUseBroker write SetUseBroker;
  51.   end;
  52.  
  53. implementation
  54.  
  55. constructor TMIDASConnection.Create(AOwner: TComponent);
  56. begin
  57.   inherited Create(AOwner);
  58.   FServerPort := 211;
  59. end;
  60.  
  61. procedure TMIDASConnection.DoConnect;
  62.  
  63.   procedure InitConnection(Dest: TDispatchConnection);
  64.   begin
  65.     with Dest do
  66.     begin
  67.       ServerName := Self.ServerName;
  68.       ServerGUID := Self.ServerGUID;
  69.     end;
  70.   end;
  71.  
  72. var
  73.   i: Integer;
  74. begin
  75.   case ConnectType of
  76.     ctDCOM: inherited DoConnect;
  77.     ctOLEnterprise:
  78.     begin
  79.       FSubConnection := TOLEnterpriseConnection.Create(Self);
  80.       try
  81.         with FSubConnection as TOLEnterpriseConnection do
  82.         begin
  83.           InitConnection(FSubConnection);
  84.           if UseBroker then
  85.             BrokerName := Self.ComputerName else
  86.             ComputerName := Self.ComputerName;
  87.           Connected := True;
  88.           Self.SetAppServer(AppServer);
  89.         end;
  90.       except
  91.         FSubConnection.Free;
  92.         raise;
  93.       end;
  94.     end;
  95.     ctSockets:
  96.     begin
  97.       FSubConnection := TSocketConnection.Create(Self);
  98.       try
  99.         with FSubConnection as TSocketConnection do
  100.         begin
  101.           for i := 1 to Length(Self.ComputerName) do
  102.             if not (Self.ComputerName[i] in ['0'..'9','.']) then
  103.             begin
  104.               Host := Self.ComputerName;
  105.               break;
  106.             end;
  107.           InitConnection(FSubConnection);
  108.           if Host = '' then
  109.             Address := Self.ComputerName;
  110.           Port := Self.ServerPort;
  111.           Connected := True;
  112.           Self.SetAppServer(AppServer);
  113.         end;
  114.       except
  115.         FSubConnection.Free;
  116.         raise;
  117.       end;
  118.     end;
  119.   end;
  120. end;
  121.  
  122. procedure TMIDASConnection.DoDisconnect;
  123. begin
  124.   inherited DoDisconnect;
  125.   FSubConnection.Free;
  126.   FSubConnection := nil;
  127. end;
  128.  
  129. procedure TMIDASConnection.SetConnectType(Value: TConnectType);
  130. begin
  131.   if Value <> FConnectType then
  132.   begin
  133.     SetConnected(False);
  134.     FConnectType := Value;
  135.   end;
  136. end;
  137.  
  138. procedure TMIDASConnection.SetUseBroker(Value: Boolean);
  139. begin
  140.   if Value <> FUseBroker then
  141.   begin
  142.     FUseBroker := Value;
  143.     SetConnected(False);
  144.   end;
  145. end;
  146.  
  147. end.
  148.