home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / DEMOS / ACTIVEX / DELCTRLS / DATEIMPL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-04  |  10.3 KB  |  375 lines

  1. unit DateImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelC_TLB, ComCtrls;
  8.  
  9. type
  10.   TDateTimePickerX = class(TActiveXControl, IDateTimePickerX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TDateTimePicker;
  14.     FEvents: IDateTimePickerXEvents;
  15.     procedure ChangeEvent(Sender: TObject);
  16.     procedure ClickEvent(Sender: TObject);
  17.     procedure CloseUpEvent(Sender: TObject);
  18.     procedure DblClickEvent(Sender: TObject);
  19.     procedure DropDownEvent(Sender: TObject);
  20.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  21.     procedure UserInputEvent(Sender: TObject; const UserString: String;
  22.       var DateAndTime: TDateTime; var AllowChange: Boolean);
  23.   protected
  24.     { Protected declarations }
  25.     procedure InitializeControl; override;
  26.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  27.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  28.     function Get_CalAlignment: TxDTCalAlignment; safecall;
  29.     function Get_Checked: WordBool; safecall;
  30.     function Get_Color: TColor; safecall;
  31.     function Get_Cursor: Smallint; safecall;
  32.     function Get_Date: Double; safecall;
  33.     function Get_DateFormat: TxDTDateFormat; safecall;
  34.     function Get_DateMode: TxDTDateMode; safecall;
  35.     function Get_DragCursor: Smallint; safecall;
  36.     function Get_DragMode: TxDragMode; safecall;
  37.     function Get_Enabled: WordBool; safecall;
  38.     function Get_Font: Font; safecall;
  39.     function Get_ImeMode: TxImeMode; safecall;
  40.     function Get_ImeName: WideString; safecall;
  41.     function Get_Kind: TxDateTimeKind; safecall;
  42.     function Get_MaxDate: Double; safecall;
  43.     function Get_MinDate: Double; safecall;
  44.     function Get_ParentColor: WordBool; safecall;
  45.     function Get_ParseInput: WordBool; safecall;
  46.     function Get_ShowCheckbox: WordBool; safecall;
  47.     function Get_Time: Double; safecall;
  48.     function Get_Visible: WordBool; safecall;
  49.     procedure AboutBox; safecall;
  50.     procedure Set_CalAlignment(Value: TxDTCalAlignment); safecall;
  51.     procedure Set_Checked(Value: WordBool); safecall;
  52.     procedure Set_Color(Value: TColor); safecall;
  53.     procedure Set_Cursor(Value: Smallint); safecall;
  54.     procedure Set_Date(Value: Double); safecall;
  55.     procedure Set_DateFormat(Value: TxDTDateFormat); safecall;
  56.     procedure Set_DateMode(Value: TxDTDateMode); safecall;
  57.     procedure Set_DragCursor(Value: Smallint); safecall;
  58.     procedure Set_DragMode(Value: TxDragMode); safecall;
  59.     procedure Set_Enabled(Value: WordBool); safecall;
  60.     procedure Set_Font(const Value: Font); safecall;
  61.     procedure Set_ImeMode(Value: TxImeMode); safecall;
  62.     procedure Set_ImeName(const Value: WideString); safecall;
  63.     procedure Set_Kind(Value: TxDateTimeKind); safecall;
  64.     procedure Set_MaxDate(Value: Double); safecall;
  65.     procedure Set_MinDate(Value: Double); safecall;
  66.     procedure Set_ParentColor(Value: WordBool); safecall;
  67.     procedure Set_ParseInput(Value: WordBool); safecall;
  68.     procedure Set_ShowCheckbox(Value: WordBool); safecall;
  69.     procedure Set_Time(Value: Double); safecall;
  70.     procedure Set_Visible(Value: WordBool); safecall;
  71.   end;
  72.  
  73. implementation
  74.  
  75. uses About8;
  76.  
  77. { TDateTimePickerX }
  78.  
  79. procedure TDateTimePickerX.InitializeControl;
  80. begin
  81.   FDelphiControl := Control as TDateTimePicker;
  82.   FDelphiControl.OnChange := ChangeEvent;
  83.   FDelphiControl.OnClick := ClickEvent;
  84.   FDelphiControl.OnCloseUp := CloseUpEvent;
  85.   FDelphiControl.OnDblClick := DblClickEvent;
  86.   FDelphiControl.OnDropDown := DropDownEvent;
  87.   FDelphiControl.OnKeyPress := KeyPressEvent;
  88.   FDelphiControl.OnUserInput := UserInputEvent;
  89. end;
  90.  
  91. procedure TDateTimePickerX.EventSinkChanged(const EventSink: IUnknown);
  92. begin
  93.   FEvents := EventSink as IDateTimePickerXEvents;
  94. end;
  95.  
  96. procedure TDateTimePickerX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  97. begin
  98.   { Define property pages here.  Property pages are defined by calling
  99.     DefinePropertyPage with the class id of the page.  For example,
  100.       DefinePropertyPage(Class_DateTimePickerXPage); }
  101. end;
  102.  
  103. function TDateTimePickerX.Get_CalAlignment: TxDTCalAlignment;
  104. begin
  105.   Result := Ord(FDelphiControl.CalAlignment);
  106. end;
  107.  
  108. function TDateTimePickerX.Get_Checked: WordBool;
  109. begin
  110.   Result := FDelphiControl.Checked;
  111. end;
  112.  
  113. function TDateTimePickerX.Get_Color: TColor;
  114. begin
  115.   Result := FDelphiControl.Color;
  116. end;
  117.  
  118. function TDateTimePickerX.Get_Cursor: Smallint;
  119. begin
  120.   Result := Smallint(FDelphiControl.Cursor);
  121. end;
  122.  
  123. function TDateTimePickerX.Get_Date: Double;
  124. begin
  125.   Result := Double(FDelphiControl.Date);
  126. end;
  127.  
  128. function TDateTimePickerX.Get_DateFormat: TxDTDateFormat;
  129. begin
  130.   Result := Ord(FDelphiControl.DateFormat);
  131. end;
  132.  
  133. function TDateTimePickerX.Get_DateMode: TxDTDateMode;
  134. begin
  135.   Result := Ord(FDelphiControl.DateMode);
  136. end;
  137.  
  138. function TDateTimePickerX.Get_DragCursor: Smallint;
  139. begin
  140.   Result := Smallint(FDelphiControl.DragCursor);
  141. end;
  142.  
  143. function TDateTimePickerX.Get_DragMode: TxDragMode;
  144. begin
  145.   Result := Ord(FDelphiControl.DragMode);
  146. end;
  147.  
  148. function TDateTimePickerX.Get_Enabled: WordBool;
  149. begin
  150.   Result := FDelphiControl.Enabled;
  151. end;
  152.  
  153. function TDateTimePickerX.Get_Font: Font;
  154. begin
  155.   GetOleFont(FDelphiControl.Font, Result);
  156. end;
  157.  
  158. function TDateTimePickerX.Get_ImeMode: TxImeMode;
  159. begin
  160.   Result := Ord(FDelphiControl.ImeMode);
  161. end;
  162.  
  163. function TDateTimePickerX.Get_ImeName: WideString;
  164. begin
  165.   Result := WideString(FDelphiControl.ImeName);
  166. end;
  167.  
  168. function TDateTimePickerX.Get_Kind: TxDateTimeKind;
  169. begin
  170.   Result := Ord(FDelphiControl.Kind);
  171. end;
  172.  
  173. function TDateTimePickerX.Get_MaxDate: Double;
  174. begin
  175.   Result := Double(FDelphiControl.MaxDate);
  176. end;
  177.  
  178. function TDateTimePickerX.Get_MinDate: Double;
  179. begin
  180.   Result := Double(FDelphiControl.MinDate);
  181. end;
  182.  
  183. function TDateTimePickerX.Get_ParentColor: WordBool;
  184. begin
  185.   Result := FDelphiControl.ParentColor;
  186. end;
  187.  
  188. function TDateTimePickerX.Get_ParseInput: WordBool;
  189. begin
  190.   Result := FDelphiControl.ParseInput;
  191. end;
  192.  
  193. function TDateTimePickerX.Get_ShowCheckbox: WordBool;
  194. begin
  195.   Result := FDelphiControl.ShowCheckbox;
  196. end;
  197.  
  198. function TDateTimePickerX.Get_Time: Double;
  199. begin
  200.   Result := Double(FDelphiControl.Time);
  201. end;
  202.  
  203. function TDateTimePickerX.Get_Visible: WordBool;
  204. begin
  205.   Result := FDelphiControl.Visible;
  206. end;
  207.  
  208. procedure TDateTimePickerX.AboutBox;
  209. begin
  210.   ShowDateTimePickerXAbout;
  211. end;
  212.  
  213. procedure TDateTimePickerX.Set_CalAlignment(Value: TxDTCalAlignment);
  214. begin
  215.   FDelphiControl.CalAlignment := TDTCalAlignment(Value);
  216. end;
  217.  
  218. procedure TDateTimePickerX.Set_Checked(Value: WordBool);
  219. begin
  220.   FDelphiControl.Checked := Value;
  221. end;
  222.  
  223. procedure TDateTimePickerX.Set_Color(Value: TColor);
  224. begin
  225.   FDelphiControl.Color := Value;
  226. end;
  227.  
  228. procedure TDateTimePickerX.Set_Cursor(Value: Smallint);
  229. begin
  230.   FDelphiControl.Cursor := TCursor(Value);
  231. end;
  232.  
  233. procedure TDateTimePickerX.Set_Date(Value: Double);
  234. begin
  235.   FDelphiControl.Date := TDate(Value);
  236. end;
  237.  
  238. procedure TDateTimePickerX.Set_DateFormat(Value: TxDTDateFormat);
  239. begin
  240.   FDelphiControl.DateFormat := TDTDateFormat(Value);
  241. end;
  242.  
  243. procedure TDateTimePickerX.Set_DateMode(Value: TxDTDateMode);
  244. begin
  245.   FDelphiControl.DateMode := TDTDateMode(Value);
  246. end;
  247.  
  248. procedure TDateTimePickerX.Set_DragCursor(Value: Smallint);
  249. begin
  250.   FDelphiControl.DragCursor := TCursor(Value);
  251. end;
  252.  
  253. procedure TDateTimePickerX.Set_DragMode(Value: TxDragMode);
  254. begin
  255.   FDelphiControl.DragMode := TDragMode(Value);
  256. end;
  257.  
  258. procedure TDateTimePickerX.Set_Enabled(Value: WordBool);
  259. begin
  260.   FDelphiControl.Enabled := Value;
  261. end;
  262.  
  263. procedure TDateTimePickerX.Set_Font(const Value: Font);
  264. begin
  265.   SetOleFont(FDelphiControl.Font, Value);
  266. end;
  267.  
  268. procedure TDateTimePickerX.Set_ImeMode(Value: TxImeMode);
  269. begin
  270.   FDelphiControl.ImeMode := TImeMode(Value);
  271. end;
  272.  
  273. procedure TDateTimePickerX.Set_ImeName(const Value: WideString);
  274. begin
  275.   FDelphiControl.ImeName := TImeName(Value);
  276. end;
  277.  
  278. procedure TDateTimePickerX.Set_Kind(Value: TxDateTimeKind);
  279. begin
  280.   FDelphiControl.Kind := TDateTimeKind(Value);
  281. end;
  282.  
  283. procedure TDateTimePickerX.Set_MaxDate(Value: Double);
  284. begin
  285.   FDelphiControl.MaxDate := TDate(Value);
  286. end;
  287.  
  288. procedure TDateTimePickerX.Set_MinDate(Value: Double);
  289. begin
  290.   FDelphiControl.MinDate := TDate(Value);
  291. end;
  292.  
  293. procedure TDateTimePickerX.Set_ParentColor(Value: WordBool);
  294. begin
  295.   FDelphiControl.ParentColor := Value;
  296. end;
  297.  
  298. procedure TDateTimePickerX.Set_ParseInput(Value: WordBool);
  299. begin
  300.   FDelphiControl.ParseInput := Value;
  301. end;
  302.  
  303. procedure TDateTimePickerX.Set_ShowCheckbox(Value: WordBool);
  304. begin
  305.   FDelphiControl.ShowCheckbox := Value;
  306. end;
  307.  
  308. procedure TDateTimePickerX.Set_Time(Value: Double);
  309. begin
  310.   FDelphiControl.Time := TTime(Value);
  311. end;
  312.  
  313. procedure TDateTimePickerX.Set_Visible(Value: WordBool);
  314. begin
  315.   FDelphiControl.Visible := Value;
  316. end;
  317.  
  318. procedure TDateTimePickerX.ChangeEvent(Sender: TObject);
  319. begin
  320.   if FEvents <> nil then FEvents.OnChange;
  321. end;
  322.  
  323. procedure TDateTimePickerX.ClickEvent(Sender: TObject);
  324. begin
  325.   if FEvents <> nil then FEvents.OnClick;
  326. end;
  327.  
  328. procedure TDateTimePickerX.CloseUpEvent(Sender: TObject);
  329. begin
  330.   if FEvents <> nil then FEvents.OnCloseUp;
  331. end;
  332.  
  333. procedure TDateTimePickerX.DblClickEvent(Sender: TObject);
  334. begin
  335.   if FEvents <> nil then FEvents.OnDblClick;
  336. end;
  337.  
  338. procedure TDateTimePickerX.DropDownEvent(Sender: TObject);
  339. begin
  340.   if FEvents <> nil then FEvents.OnDropDown;
  341. end;
  342.  
  343. procedure TDateTimePickerX.KeyPressEvent(Sender: TObject; var Key: Char);
  344. var
  345.   TempKey: Smallint;
  346. begin
  347.   TempKey := Smallint(Key);
  348.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  349.   Key := Char(TempKey);
  350. end;
  351.  
  352. procedure TDateTimePickerX.UserInputEvent(Sender: TObject;
  353.   const UserString: String; var DateAndTime: TDateTime;
  354.   var AllowChange: Boolean);
  355. var
  356.   TempDateAndTime: Double;
  357.   TempAllowChange: WordBool;
  358. begin
  359.   TempDateAndTime := Double(DateAndTime);
  360.   TempAllowChange := WordBool(AllowChange);
  361.   if FEvents <> nil then FEvents.OnUserInput(WideString(UserString), TempDateAndTime, TempAllowChange);
  362.   AllowChange := Boolean(TempAllowChange);
  363. end;
  364.  
  365. initialization
  366.   TActiveXControlFactory.Create(
  367.     ComServer,
  368.     TDateTimePickerX,
  369.     TDateTimePicker,
  370.     Class_DateTimePickerX,
  371.     8,
  372.     '{FA7B8346-9ED7-11D0-AA40-444553540000}',
  373.     0);
  374. end.
  375.