home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Demos / Midas / Setparam / clientfr.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  2KB  |  89 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 how to set parameters for a query on the server.
  8. }
  9.  
  10. interface
  11.  
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   Db, DBClient, StdCtrls, DBCtrls, Grids, DBGrids, ExtCtrls, MConnect;
  15.  
  16. type
  17.   TForm1 = class(TForm)
  18.     DataSource1: TDataSource;
  19.     DBGrid1: TDBGrid;
  20.     StartDate: TEdit;
  21.     EndDate: TEdit;
  22.     DBImage1: TDBImage;
  23.     DBMemo1: TDBMemo;
  24.     Events: TClientDataSet;
  25.     EventsEventNo: TIntegerField;
  26.     EventsVenueNo: TIntegerField;
  27.     EventsEvent_Name: TStringField;
  28.     EventsEvent_Date: TDateField;
  29.     EventsEvent_Time: TTimeField;
  30.     EventsEvent_Description: TMemoField;
  31.     EventsTicket_price: TCurrencyField;
  32.     EventsEvent_Photo: TGraphicField;
  33.     Label1: TLabel;
  34.     Label2: TLabel;
  35.     Label3: TLabel;
  36.     Label4: TLabel;
  37.     ShowEvents: TButton;
  38.     Bevel1: TBevel;
  39.     RemoteServer: TDCOMConnection;
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure ShowEventsClick(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. var
  49.   Form1: TForm1;
  50.  
  51. implementation
  52.  
  53. {$R *.DFM}
  54.  
  55.  
  56. procedure TForm1.FormCreate(Sender: TObject);
  57. begin
  58.   { Initialize the edit controls with some dates so the user can
  59.     just click the button to see some data }
  60.   StartDate.Text := DateToStr(EncodeDate(96, 6, 19));
  61.   EndDate.Text := DateToStr(EncodeDate(96, 6, 21));
  62. end;
  63.  
  64. procedure TForm1.ShowEventsClick(Sender: TObject);
  65. begin
  66.  
  67. { The query on the server looks like this:
  68.  
  69.      select * from events where
  70.        Event_Date >= :Start_Date and
  71.        Event_Date <= :End_Date;
  72.  
  73.   The Events ClientDataSet has the parameters from the server set up in the
  74.   Params property.  At design time, you can right click on a ClientDataSet and
  75.   select "Fetch Params" to initialize the params from a TQuery or TStoredProc
  76.   on the server.  At run-time you can call TClientDataSet.FetchParams to
  77.   initialize the params from the server.  Or you can set the params up manually
  78.   by adding them yourself.
  79.  
  80. }
  81.  
  82.   Events.Close;
  83.   Events.Params.ParamByName('Start_Date').AsDateTime := StrToDateTime(StartDate.Text);
  84.   Events.Params.ParamByName('End_Date').AsDateTime := StrToDateTime(EndDate.Text);
  85.   Events.Open;
  86. end;
  87.  
  88. end.
  89.