home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Demos / Midas / Adhoc / clientfr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  2.3 KB  |  90 lines

  1. unit ClientFr;
  2.  
  3. {
  4.   This is the client portion of a MIDAS demo.  Make sure that you compile and
  5.   run the server project before trying to run this probject.
  6.  
  7.   This project demonstrates dynamically passing SQL to the server using the
  8.   Provider.DataRequest event.
  9. }
  10.  
  11. interface
  12.  
  13. uses
  14.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  15.   Db, DBClient, ExtCtrls, Grids, DBGrids, StdCtrls, MConnect;
  16.  
  17. type
  18.   TForm1 = class(TForm)
  19.     SQL: TMemo;
  20.     Label1: TLabel;
  21.     DatabaseName: TComboBox;
  22.     RunButton: TButton;
  23.     DataSource1: TDataSource;
  24.     DBGrid1: TDBGrid;
  25.     Bevel1: TBevel;
  26.     RemoteServer: TDCOMConnection;
  27.     ClientData: TClientDataSet;
  28.     procedure DatabaseNameClick(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure RunButtonClick(Sender: TObject);
  31.   private
  32.     { Private declarations }
  33.   public
  34.     { Public declarations }
  35.   end;
  36.  
  37. var
  38.   Form1: TForm1;
  39.  
  40. implementation
  41.  
  42. {$R *.DFM}
  43.  
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. var
  46.   I: Integer;
  47.   DBNames: OleVariant;
  48. begin
  49.   { Connect to the server and get a list of available database names }
  50.   RemoteServer.Connected := True;
  51.   DBNames := RemoteServer.AppServer.GetDatabaseNames;
  52.   if VarIsArray(DBNames) then
  53.     for I := 0 to VarArrayHighBound(DBNames, 1) do
  54.       DatabaseName.Items.Add(DBNames[I]);
  55.   DatabaseNameClick(Self);
  56. end;
  57.  
  58. procedure TForm1.RunButtonClick(Sender: TObject);
  59. begin
  60.   { Send the query string to the server and try to open the client dataset }
  61.   ClientData.Close;
  62.   ClientData.CommandText := SQL.Lines.Text;
  63.   ClientData.Open;
  64. end;
  65.  
  66. procedure TForm1.DatabaseNameClick(Sender: TObject);
  67. var
  68.   Password: string;
  69. begin
  70.   { Change the database name on the server }
  71.   if DatabaseName.Text <> '' then
  72.   begin
  73.     ClientData.Close;
  74.     try
  75.       RemoteServer.AppServer.SetDatabaseName(DatabaseName.Text, '');
  76.     except
  77.       { This is a crude mechanism for getting the password on SQL Databases }
  78.       on E: Exception do
  79.         if E.Message = 'Password Required' then
  80.         begin
  81.           if InputQuery(E.Message, 'Enter password', Password) then
  82.             RemoteServer.AppServer.SetDatabaseName(DatabaseName.Text, Password);
  83.         end else
  84.           raise;
  85.     end;
  86.   end;
  87. end;
  88.  
  89. end.
  90.