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

  1. unit EmpEdImp;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ActiveX, AxCtrls, EmpE_TLB, DBClient, Db, ComCtrls, ExtCtrls,
  8.   DBCtrls, StdCtrls, Mask, MConnect;
  9.  
  10. type
  11.   TEmpEditForm = class(TActiveForm, IEmpEditForm)
  12.     Label2: TLabel;
  13.     UpdateButton: TButton;
  14.     UndoButton: TButton;
  15.     QueryButton: TButton;
  16.     DBText1: TDBText;
  17.     FirstName: TDBEdit;
  18.     LastName: TDBEdit;
  19.     PhoneExt: TDBEdit;
  20.     HireDate: TDBEdit;
  21.     Salary: TDBEdit;
  22.     EmpData: TDataSource;
  23.     DBNavigator1: TDBNavigator;
  24.     Employees: TClientDataSet;
  25.     MidasConnection: TDCOMConnection;
  26.     RecInd: TLabel;
  27.     procedure QueryButtonClick(Sender: TObject);
  28.     procedure UpdateButtonClick(Sender: TObject);
  29.     procedure UndoButtonClick(Sender: TObject);
  30.     procedure EmployeesReconcileError(DataSet: TClientDataSet;
  31.      E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  32.     procedure EmpDataDataChange(Sender: TObject; Field: TField);
  33.   private
  34.     { Private declarations }
  35.     FEvents: IEmpEditFormEvents;
  36.     procedure ActivateEvent(Sender: TObject);
  37.     procedure ClickEvent(Sender: TObject);
  38.     procedure CreateEvent(Sender: TObject);
  39.     procedure DblClickEvent(Sender: TObject);
  40.     procedure DeactivateEvent(Sender: TObject);
  41.     procedure DestroyEvent(Sender: TObject);
  42.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  43.     procedure PaintEvent(Sender: TObject);
  44.   protected
  45.     { Protected declarations }
  46.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  47.     procedure Initialize; override;
  48.     function Get_Active: WordBool; safecall;
  49.     function Get_AutoScroll: WordBool; safecall;
  50.     function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
  51.     function Get_Caption: WideString; safecall;
  52.     function Get_Color: OLE_Color; safecall;
  53.     function Get_Cursor: Smallint; safecall;
  54.     function Get_DropTarget: WordBool; safecall;
  55.     function Get_Enabled: WordBool; safecall;
  56.     function Get_Font: Font; safecall;
  57.     function Get_HelpFile: WideString; safecall;
  58.     function Get_KeyPreview: WordBool; safecall;
  59.     function Get_PixelsPerInch: Integer; safecall;
  60.     function Get_PrintScale: TxPrintScale; safecall;
  61.     function Get_Scaled: WordBool; safecall;
  62.     function Get_Visible: WordBool; safecall;
  63.     function Get_WindowState: TxWindowState; safecall;
  64.     procedure Set_AutoScroll(Value: WordBool); safecall;
  65.     procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
  66.     procedure Set_Caption(const Value: WideString); safecall;
  67.     procedure Set_Color(Value: OLE_Color); safecall;
  68.     procedure Set_Cursor(Value: Smallint); safecall;
  69.     procedure Set_DropTarget(Value: WordBool); safecall;
  70.     procedure Set_Enabled(Value: WordBool); safecall;
  71.     procedure Set_Font(const Value: Font); safecall;
  72.     procedure Set_HelpFile(const Value: WideString); safecall;
  73.     procedure Set_KeyPreview(Value: WordBool); safecall;
  74.     procedure Set_PixelsPerInch(Value: Integer); safecall;
  75.     procedure Set_PrintScale(Value: TxPrintScale); safecall;
  76.     procedure Set_Scaled(Value: WordBool); safecall;
  77.     procedure Set_Visible(Value: WordBool); safecall;
  78.     procedure Set_WindowState(Value: TxWindowState); safecall;
  79.   public
  80.     { Public declarations }
  81.   end;
  82.  
  83. implementation
  84.  
  85. uses RecError, ComServ;
  86.  
  87. {$R *.DFM}
  88.  
  89. { TEmpEditForm }
  90.  
  91. procedure TEmpEditForm.EventSinkChanged(const EventSink: IUnknown);
  92. begin
  93.   FEvents := EventSink as IEmpEditFormEvents;
  94. end;
  95.  
  96. procedure TEmpEditForm.Initialize;
  97. begin
  98.   OnActivate := ActivateEvent;
  99.   OnClick := ClickEvent;
  100.   OnCreate := CreateEvent;
  101.   OnDblClick := DblClickEvent;
  102.   OnDeactivate := DeactivateEvent;
  103.   OnDestroy := DestroyEvent;
  104.   OnKeyPress := KeyPressEvent;
  105.   OnPaint := PaintEvent;
  106. end;
  107.  
  108. function TEmpEditForm.Get_Active: WordBool;
  109. begin
  110.   Result := Active;
  111. end;
  112.  
  113. function TEmpEditForm.Get_AutoScroll: WordBool;
  114. begin
  115.   Result := AutoScroll;
  116. end;
  117.  
  118. function TEmpEditForm.Get_AxBorderStyle: TxActiveFormBorderStyle;
  119. begin
  120.   Result := Ord(AxBorderStyle);
  121. end;
  122.  
  123. function TEmpEditForm.Get_Caption: WideString;
  124. begin
  125.   Result := WideString(Caption);
  126. end;
  127.  
  128. function TEmpEditForm.Get_Color: OLE_COLOR;
  129. begin
  130.   Result := Color;
  131. end;
  132.  
  133. function TEmpEditForm.Get_Cursor: Smallint;
  134. begin
  135.   Result := Smallint(Cursor);
  136. end;
  137.  
  138. function TEmpEditForm.Get_DropTarget: WordBool;
  139. begin
  140.   Result := DropTarget;
  141. end;
  142.  
  143. function TEmpEditForm.Get_Enabled: WordBool;
  144. begin
  145.   Result := Enabled;
  146. end;
  147.  
  148. function TEmpEditForm.Get_Font: Font;
  149. begin
  150.   GetOleFont(Font, Result);
  151. end;
  152.  
  153. function TEmpEditForm.Get_HelpFile: WideString;
  154. begin
  155.   Result := WideString(HelpFile);
  156. end;
  157.  
  158. function TEmpEditForm.Get_KeyPreview: WordBool;
  159. begin
  160.   Result := KeyPreview;
  161. end;
  162.  
  163. function TEmpEditForm.Get_PixelsPerInch: Integer;
  164. begin
  165.   Result := PixelsPerInch;
  166. end;
  167.  
  168. function TEmpEditForm.Get_PrintScale: TxPrintScale;
  169. begin
  170.   Result := Ord(PrintScale);
  171. end;
  172.  
  173. function TEmpEditForm.Get_Scaled: WordBool;
  174. begin
  175.   Result := Scaled;
  176. end;
  177.  
  178. function TEmpEditForm.Get_Visible: WordBool;
  179. begin
  180.   Result := Visible;
  181. end;
  182.  
  183. function TEmpEditForm.Get_WindowState: TxWindowState;
  184. begin
  185.   Result := Ord(WindowState);
  186. end;
  187.  
  188. procedure TEmpEditForm.Set_AutoScroll(Value: WordBool);
  189. begin
  190.   AutoScroll := Value;
  191. end;
  192.  
  193. procedure TEmpEditForm.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
  194. begin
  195.   AxBorderStyle := TActiveFormBorderStyle(Value);
  196. end;
  197.  
  198. procedure TEmpEditForm.Set_Caption(const Value: WideString);
  199. begin
  200.   Caption := TCaption(Value);
  201. end;
  202.  
  203. procedure TEmpEditForm.Set_Color(Value: OLE_COLOR);
  204. begin
  205.   Color := Value;
  206. end;
  207.  
  208. procedure TEmpEditForm.Set_Cursor(Value: Smallint);
  209. begin
  210.   Cursor := TCursor(Value);
  211. end;
  212.  
  213. procedure TEmpEditForm.Set_DropTarget(Value: WordBool);
  214. begin
  215.   DropTarget := Value;
  216. end;
  217.  
  218. procedure TEmpEditForm.Set_Enabled(Value: WordBool);
  219. begin
  220.   Enabled := Value;
  221. end;
  222.  
  223. procedure TEmpEditForm.Set_Font(const Value: Font);
  224. begin
  225.   SetOleFont(Font, Value);
  226. end;
  227.  
  228. procedure TEmpEditForm.Set_HelpFile(const Value: WideString);
  229. begin
  230.   HelpFile := String(Value);
  231. end;
  232.  
  233. procedure TEmpEditForm.Set_KeyPreview(Value: WordBool);
  234. begin
  235.   KeyPreview := Value;
  236. end;
  237.  
  238. procedure TEmpEditForm.Set_PixelsPerInch(Value: Integer);
  239. begin
  240.   PixelsPerInch := Value;
  241. end;
  242.  
  243. procedure TEmpEditForm.Set_PrintScale(Value: TxPrintScale);
  244. begin
  245.   PrintScale := TPrintScale(Value);
  246. end;
  247.  
  248. procedure TEmpEditForm.Set_Scaled(Value: WordBool);
  249. begin
  250.   Scaled := Value;
  251. end;
  252.  
  253. procedure TEmpEditForm.Set_Visible(Value: WordBool);
  254. begin
  255.   Visible := Value;
  256. end;
  257.  
  258. procedure TEmpEditForm.Set_WindowState(Value: TxWindowState);
  259. begin
  260.   WindowState := TWindowState(Value);
  261. end;
  262.  
  263. procedure TEmpEditForm.ActivateEvent(Sender: TObject);
  264. begin
  265.   if FEvents <> nil then FEvents.OnActivate;
  266. end;
  267.  
  268. procedure TEmpEditForm.ClickEvent(Sender: TObject);
  269. begin
  270.   if FEvents <> nil then FEvents.OnClick;
  271. end;
  272.  
  273. procedure TEmpEditForm.CreateEvent(Sender: TObject);
  274. begin
  275.   if FEvents <> nil then FEvents.OnCreate;
  276. end;
  277.  
  278. procedure TEmpEditForm.DblClickEvent(Sender: TObject);
  279. begin
  280.   if FEvents <> nil then FEvents.OnDblClick;
  281. end;
  282.  
  283. procedure TEmpEditForm.DeactivateEvent(Sender: TObject);
  284. begin
  285.   if FEvents <> nil then FEvents.OnDeactivate;
  286. end;
  287.  
  288. procedure TEmpEditForm.DestroyEvent(Sender: TObject);
  289. begin
  290.   if FEvents <> nil then FEvents.OnDestroy;
  291. end;
  292.  
  293. procedure TEmpEditForm.KeyPressEvent(Sender: TObject; var Key: Char);
  294. var
  295.   TempKey: Smallint;
  296. begin
  297.   TempKey := Smallint(Key);
  298.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  299.   Key := Char(TempKey);
  300. end;
  301.  
  302. procedure TEmpEditForm.PaintEvent(Sender: TObject);
  303. begin
  304.   if FEvents <> nil then FEvents.OnPaint;
  305. end;
  306.  
  307. { ========================================================================== }
  308.  
  309. procedure TEmpEditForm.QueryButtonClick(Sender: TObject);
  310. begin
  311.  
  312. { Get data from the server.  The number of records returned is dependent on
  313.   the PacketRecords property of TClientDataSet.  If PacketRecords is set
  314.   to -1 then all records are returned.  Otherwise, as the user scrolls
  315.   through the data, additional records are returned in separate data packets. }
  316.  
  317.   Employees.Close;
  318.   Employees.Open;
  319.  
  320. end;
  321.  
  322. procedure TEmpEditForm.UpdateButtonClick(Sender: TObject);
  323. begin
  324.  
  325. { Apply any edits.  The parameter indicates the number of errors which
  326.   are allowed before the updating is aborted.  A value of -1 indicates that
  327.   all successful updates be applied regardless of the number of errors. }
  328.  
  329.   Employees.ApplyUpdates(-1);
  330.  
  331. end;
  332.  
  333. procedure TEmpEditForm.UndoButtonClick(Sender: TObject);
  334. begin
  335.  
  336. { Here we demonstrate a new feature in TClientDataSet, the ability to undo
  337.   changes in reverse order.  The parameter indicates if the cursor should
  338.   be repositioned to the record association with the change. }
  339.  
  340.  
  341.   Employees.UndoLastChange(True);
  342.  
  343. end;
  344.  
  345. procedure TEmpEditForm.EmployeesReconcileError(DataSet: TClientDataSet;
  346.   E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  347. begin
  348.  
  349. { This is the event handler which is called when there are errors during the
  350.   update process.  To demonstrate, you can create an error by running two
  351.   copies of this application and modifying the same record in each one.
  352.   Here we use the standard reconcile error dialog from the object repository. }
  353.  
  354.   Action := HandleReconcileError(DataSet, UpdateKind, E);
  355. end;
  356.  
  357. procedure TEmpEditForm.EmpDataDataChange(Sender: TObject; Field: TField);
  358. begin
  359.  
  360. { This code is used to update the status bar to show the number of records
  361.   that have been retrieved an our relative position with the dataset. }
  362.  
  363.   with Employees do
  364.     if Active then
  365.       RecInd.Caption := Format(' %d of %d', [RecNo, RecordCount]);
  366.  
  367. end;
  368. initialization
  369.   TActiveFormFactory.Create(
  370.     ComServer,
  371.     TActiveFormControl,
  372.     TEmpEditForm,
  373.     Class_EmpEditForm,
  374.     1,
  375.     '',
  376.     OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL);
  377. end.
  378.