home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / ACTIVEX / DELCTRLS / datetimepickerimpl1.pas < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  14KB  |  497 lines

  1. unit DateTimePickerImpl1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelCtrls_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 DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  26.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  27.     procedure InitializeControl; override;
  28.     function ClassNameIs(const Name: WideString): WordBool; safecall;
  29.     function DrawTextBiDiModeFlags(Flags: Integer): Integer; safecall;
  30.     function DrawTextBiDiModeFlagsReadingOnly: Integer; safecall;
  31.     function Get_BiDiMode: TxBiDiMode; safecall;
  32.     function Get_CalAlignment: TxDTCalAlignment; safecall;
  33.     function Get_Checked: WordBool; safecall;
  34.     function Get_Color: OLE_COLOR; safecall;
  35.     function Get_Cursor: Smallint; safecall;
  36.     function Get_Date: Double; safecall;
  37.     function Get_DateFormat: TxDTDateFormat; safecall;
  38.     function Get_DateMode: TxDTDateMode; safecall;
  39.     function Get_DateTime: Double; safecall;
  40.     function Get_DoubleBuffered: WordBool; safecall;
  41.     function Get_DragCursor: Smallint; safecall;
  42.     function Get_DragMode: TxDragMode; safecall;
  43.     function Get_DroppedDown: WordBool; safecall;
  44.     function Get_Enabled: WordBool; safecall;
  45.     function Get_Font: IFontDisp; safecall;
  46.     function Get_ImeMode: TxImeMode; safecall;
  47.     function Get_ImeName: WideString; safecall;
  48.     function Get_Kind: TxDateTimeKind; safecall;
  49.     function Get_MaxDate: Double; safecall;
  50.     function Get_MinDate: Double; safecall;
  51.     function Get_ParentColor: WordBool; safecall;
  52.     function Get_ParentFont: WordBool; safecall;
  53.     function Get_ParseInput: WordBool; safecall;
  54.     function Get_ShowCheckbox: WordBool; safecall;
  55.     function Get_Time: Double; safecall;
  56.     function Get_Visible: WordBool; safecall;
  57.     function GetControlsAlignment: TxAlignment; safecall;
  58.     function IsRightToLeft: WordBool; safecall;
  59.     function UseRightToLeftAlignment: WordBool; safecall;
  60.     function UseRightToLeftReading: WordBool; safecall;
  61.     function UseRightToLeftScrollBar: WordBool; safecall;
  62.     procedure _Set_Font(const Value: IFontDisp); safecall;
  63.     procedure AboutBox; safecall;
  64.     procedure FlipChildren(AllLevels: WordBool); safecall;
  65.     procedure InitiateAction; safecall;
  66.     procedure Set_BiDiMode(Value: TxBiDiMode); safecall;
  67.     procedure Set_CalAlignment(Value: TxDTCalAlignment); safecall;
  68.     procedure Set_Checked(Value: WordBool); safecall;
  69.     procedure Set_Color(Value: OLE_COLOR); safecall;
  70.     procedure Set_Cursor(Value: Smallint); safecall;
  71.     procedure Set_Date(Value: Double); safecall;
  72.     procedure Set_DateFormat(Value: TxDTDateFormat); safecall;
  73.     procedure Set_DateMode(Value: TxDTDateMode); safecall;
  74.     procedure Set_DateTime(Value: Double); safecall;
  75.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  76.     procedure Set_DragCursor(Value: Smallint); safecall;
  77.     procedure Set_DragMode(Value: TxDragMode); safecall;
  78.     procedure Set_Enabled(Value: WordBool); safecall;
  79.     procedure Set_Font(const Value: IFontDisp); safecall;
  80.     procedure Set_ImeMode(Value: TxImeMode); safecall;
  81.     procedure Set_ImeName(const Value: WideString); safecall;
  82.     procedure Set_Kind(Value: TxDateTimeKind); safecall;
  83.     procedure Set_MaxDate(Value: Double); safecall;
  84.     procedure Set_MinDate(Value: Double); safecall;
  85.     procedure Set_ParentColor(Value: WordBool); safecall;
  86.     procedure Set_ParentFont(Value: WordBool); safecall;
  87.     procedure Set_ParseInput(Value: WordBool); safecall;
  88.     procedure Set_ShowCheckbox(Value: WordBool); safecall;
  89.     procedure Set_Time(Value: Double); safecall;
  90.     procedure Set_Visible(Value: WordBool); safecall;
  91.   end;
  92.  
  93. implementation
  94.  
  95. uses ComObj, About9;
  96.  
  97. { TDateTimePickerX }
  98.  
  99. procedure TDateTimePickerX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  100. begin
  101.   { Define property pages here.  Property pages are defined by calling
  102.     DefinePropertyPage with the class id of the page.  For example,
  103.       DefinePropertyPage(Class_DateTimePickerXPage); }
  104. end;
  105.  
  106. procedure TDateTimePickerX.EventSinkChanged(const EventSink: IUnknown);
  107. begin
  108.   FEvents := EventSink as IDateTimePickerXEvents;
  109. end;
  110.  
  111. procedure TDateTimePickerX.InitializeControl;
  112. begin
  113.   FDelphiControl := Control as TDateTimePicker;
  114.   FDelphiControl.OnChange := ChangeEvent;
  115.   FDelphiControl.OnClick := ClickEvent;
  116.   FDelphiControl.OnCloseUp := CloseUpEvent;
  117.   FDelphiControl.OnDblClick := DblClickEvent;
  118.   FDelphiControl.OnDropDown := DropDownEvent;
  119.   FDelphiControl.OnKeyPress := KeyPressEvent;
  120.   FDelphiControl.OnUserInput := UserInputEvent;
  121. end;
  122.  
  123. function TDateTimePickerX.ClassNameIs(const Name: WideString): WordBool;
  124. begin
  125.   Result := FDelphiControl.ClassNameIs(Name);
  126. end;
  127.  
  128. function TDateTimePickerX.DrawTextBiDiModeFlags(Flags: Integer): Integer;
  129. begin
  130.   Result := FDelphiControl.DrawTextBiDiModeFlags(Flags);
  131. end;
  132.  
  133. function TDateTimePickerX.DrawTextBiDiModeFlagsReadingOnly: Integer;
  134. begin
  135.   Result := FDelphiControl.DrawTextBiDiModeFlagsReadingOnly;
  136. end;
  137.  
  138. function TDateTimePickerX.Get_BiDiMode: TxBiDiMode;
  139. begin
  140.   Result := Ord(FDelphiControl.BiDiMode);
  141. end;
  142.  
  143. function TDateTimePickerX.Get_CalAlignment: TxDTCalAlignment;
  144. begin
  145.   Result := Ord(FDelphiControl.CalAlignment);
  146. end;
  147.  
  148. function TDateTimePickerX.Get_Checked: WordBool;
  149. begin
  150.   Result := FDelphiControl.Checked;
  151. end;
  152.  
  153. function TDateTimePickerX.Get_Color: OLE_COLOR;
  154. begin
  155.   Result := OLE_COLOR(FDelphiControl.Color);
  156. end;
  157.  
  158. function TDateTimePickerX.Get_Cursor: Smallint;
  159. begin
  160.   Result := Smallint(FDelphiControl.Cursor);
  161. end;
  162.  
  163. function TDateTimePickerX.Get_Date: Double;
  164. begin
  165.   Result := Double(FDelphiControl.Date);
  166. end;
  167.  
  168. function TDateTimePickerX.Get_DateFormat: TxDTDateFormat;
  169. begin
  170.   Result := Ord(FDelphiControl.DateFormat);
  171. end;
  172.  
  173. function TDateTimePickerX.Get_DateMode: TxDTDateMode;
  174. begin
  175.   Result := Ord(FDelphiControl.DateMode);
  176. end;
  177.  
  178. function TDateTimePickerX.Get_DateTime: Double;
  179. begin
  180.   Result := Double(FDelphiControl.DateTime);
  181. end;
  182.  
  183. function TDateTimePickerX.Get_DoubleBuffered: WordBool;
  184. begin
  185.   Result := FDelphiControl.DoubleBuffered;
  186. end;
  187.  
  188. function TDateTimePickerX.Get_DragCursor: Smallint;
  189. begin
  190.   Result := Smallint(FDelphiControl.DragCursor);
  191. end;
  192.  
  193. function TDateTimePickerX.Get_DragMode: TxDragMode;
  194. begin
  195.   Result := Ord(FDelphiControl.DragMode);
  196. end;
  197.  
  198. function TDateTimePickerX.Get_DroppedDown: WordBool;
  199. begin
  200.   Result := FDelphiControl.DroppedDown;
  201. end;
  202.  
  203. function TDateTimePickerX.Get_Enabled: WordBool;
  204. begin
  205.   Result := FDelphiControl.Enabled;
  206. end;
  207.  
  208. function TDateTimePickerX.Get_Font: IFontDisp;
  209. begin
  210.   GetOleFont(FDelphiControl.Font, Result);
  211. end;
  212.  
  213. function TDateTimePickerX.Get_ImeMode: TxImeMode;
  214. begin
  215.   Result := Ord(FDelphiControl.ImeMode);
  216. end;
  217.  
  218. function TDateTimePickerX.Get_ImeName: WideString;
  219. begin
  220.   Result := WideString(FDelphiControl.ImeName);
  221. end;
  222.  
  223. function TDateTimePickerX.Get_Kind: TxDateTimeKind;
  224. begin
  225.   Result := Ord(FDelphiControl.Kind);
  226. end;
  227.  
  228. function TDateTimePickerX.Get_MaxDate: Double;
  229. begin
  230.   Result := Double(FDelphiControl.MaxDate);
  231. end;
  232.  
  233. function TDateTimePickerX.Get_MinDate: Double;
  234. begin
  235.   Result := Double(FDelphiControl.MinDate);
  236. end;
  237.  
  238. function TDateTimePickerX.Get_ParentColor: WordBool;
  239. begin
  240.   Result := FDelphiControl.ParentColor;
  241. end;
  242.  
  243. function TDateTimePickerX.Get_ParentFont: WordBool;
  244. begin
  245.   Result := FDelphiControl.ParentFont;
  246. end;
  247.  
  248. function TDateTimePickerX.Get_ParseInput: WordBool;
  249. begin
  250.   Result := FDelphiControl.ParseInput;
  251. end;
  252.  
  253. function TDateTimePickerX.Get_ShowCheckbox: WordBool;
  254. begin
  255.   Result := FDelphiControl.ShowCheckbox;
  256. end;
  257.  
  258. function TDateTimePickerX.Get_Time: Double;
  259. begin
  260.   Result := Double(FDelphiControl.Time);
  261. end;
  262.  
  263. function TDateTimePickerX.Get_Visible: WordBool;
  264. begin
  265.   Result := FDelphiControl.Visible;
  266. end;
  267.  
  268. function TDateTimePickerX.GetControlsAlignment: TxAlignment;
  269. begin
  270.  Result := TxAlignment(FDelphiControl.GetControlsAlignment);
  271. end;
  272.  
  273. function TDateTimePickerX.IsRightToLeft: WordBool;
  274. begin
  275.   Result := FDelphiControl.IsRightToLeft;
  276. end;
  277.  
  278. function TDateTimePickerX.UseRightToLeftAlignment: WordBool;
  279. begin
  280.   Result := FDelphiControl.UseRightToLeftAlignment;
  281. end;
  282.  
  283. function TDateTimePickerX.UseRightToLeftReading: WordBool;
  284. begin
  285.   Result := FDelphiControl.UseRightToLeftReading;
  286. end;
  287.  
  288. function TDateTimePickerX.UseRightToLeftScrollBar: WordBool;
  289. begin
  290.   Result := FDelphiControl.UseRightToLeftScrollBar;
  291. end;
  292.  
  293. procedure TDateTimePickerX._Set_Font(const Value: IFontDisp);
  294. begin
  295.   SetOleFont(FDelphiControl.Font, Value);
  296. end;
  297.  
  298. procedure TDateTimePickerX.AboutBox;
  299. begin
  300.   ShowDateTimePickerXAbout;
  301. end;
  302.  
  303. procedure TDateTimePickerX.FlipChildren(AllLevels: WordBool);
  304. begin
  305.   FDelphiControl.FlipChildren(AllLevels);
  306. end;
  307.  
  308. procedure TDateTimePickerX.InitiateAction;
  309. begin
  310.   FDelphiControl.InitiateAction;
  311. end;
  312.  
  313. procedure TDateTimePickerX.Set_BiDiMode(Value: TxBiDiMode);
  314. begin
  315.   FDelphiControl.BiDiMode := TBiDiMode(Value);
  316. end;
  317.  
  318. procedure TDateTimePickerX.Set_CalAlignment(Value: TxDTCalAlignment);
  319. begin
  320.   FDelphiControl.CalAlignment := TDTCalAlignment(Value);
  321. end;
  322.  
  323. procedure TDateTimePickerX.Set_Checked(Value: WordBool);
  324. begin
  325.   FDelphiControl.Checked := Value;
  326. end;
  327.  
  328. procedure TDateTimePickerX.Set_Color(Value: OLE_COLOR);
  329. begin
  330.   FDelphiControl.Color := TColor(Value);
  331. end;
  332.  
  333. procedure TDateTimePickerX.Set_Cursor(Value: Smallint);
  334. begin
  335.   FDelphiControl.Cursor := TCursor(Value);
  336. end;
  337.  
  338. procedure TDateTimePickerX.Set_Date(Value: Double);
  339. begin
  340.   FDelphiControl.Date := TDate(Value);
  341. end;
  342.  
  343. procedure TDateTimePickerX.Set_DateFormat(Value: TxDTDateFormat);
  344. begin
  345.   FDelphiControl.DateFormat := TDTDateFormat(Value);
  346. end;
  347.  
  348. procedure TDateTimePickerX.Set_DateMode(Value: TxDTDateMode);
  349. begin
  350.   FDelphiControl.DateMode := TDTDateMode(Value);
  351. end;
  352.  
  353. procedure TDateTimePickerX.Set_DateTime(Value: Double);
  354. begin
  355.   FDelphiControl.DateTime := TDateTime(Value);
  356. end;
  357.  
  358. procedure TDateTimePickerX.Set_DoubleBuffered(Value: WordBool);
  359. begin
  360.   FDelphiControl.DoubleBuffered := Value;
  361. end;
  362.  
  363. procedure TDateTimePickerX.Set_DragCursor(Value: Smallint);
  364. begin
  365.   FDelphiControl.DragCursor := TCursor(Value);
  366. end;
  367.  
  368. procedure TDateTimePickerX.Set_DragMode(Value: TxDragMode);
  369. begin
  370.   FDelphiControl.DragMode := TDragMode(Value);
  371. end;
  372.  
  373. procedure TDateTimePickerX.Set_Enabled(Value: WordBool);
  374. begin
  375.   FDelphiControl.Enabled := Value;
  376. end;
  377.  
  378. procedure TDateTimePickerX.Set_Font(const Value: IFontDisp);
  379. begin
  380.   SetOleFont(FDelphiControl.Font, Value);
  381. end;
  382.  
  383. procedure TDateTimePickerX.Set_ImeMode(Value: TxImeMode);
  384. begin
  385.   FDelphiControl.ImeMode := TImeMode(Value);
  386. end;
  387.  
  388. procedure TDateTimePickerX.Set_ImeName(const Value: WideString);
  389. begin
  390.   FDelphiControl.ImeName := TImeName(Value);
  391. end;
  392.  
  393. procedure TDateTimePickerX.Set_Kind(Value: TxDateTimeKind);
  394. begin
  395.   FDelphiControl.Kind := TDateTimeKind(Value);
  396. end;
  397.  
  398. procedure TDateTimePickerX.Set_MaxDate(Value: Double);
  399. begin
  400.   FDelphiControl.MaxDate := TDate(Value);
  401. end;
  402.  
  403. procedure TDateTimePickerX.Set_MinDate(Value: Double);
  404. begin
  405.   FDelphiControl.MinDate := TDate(Value);
  406. end;
  407.  
  408. procedure TDateTimePickerX.Set_ParentColor(Value: WordBool);
  409. begin
  410.   FDelphiControl.ParentColor := Value;
  411. end;
  412.  
  413. procedure TDateTimePickerX.Set_ParentFont(Value: WordBool);
  414. begin
  415.   FDelphiControl.ParentFont := Value;
  416. end;
  417.  
  418. procedure TDateTimePickerX.Set_ParseInput(Value: WordBool);
  419. begin
  420.   FDelphiControl.ParseInput := Value;
  421. end;
  422.  
  423. procedure TDateTimePickerX.Set_ShowCheckbox(Value: WordBool);
  424. begin
  425.   FDelphiControl.ShowCheckbox := Value;
  426. end;
  427.  
  428. procedure TDateTimePickerX.Set_Time(Value: Double);
  429. begin
  430.   FDelphiControl.Time := TTime(Value);
  431. end;
  432.  
  433. procedure TDateTimePickerX.Set_Visible(Value: WordBool);
  434. begin
  435.   FDelphiControl.Visible := Value;
  436. end;
  437.  
  438. procedure TDateTimePickerX.ChangeEvent(Sender: TObject);
  439. begin
  440.   if FEvents <> nil then FEvents.OnChange;
  441. end;
  442.  
  443. procedure TDateTimePickerX.ClickEvent(Sender: TObject);
  444. begin
  445.   if FEvents <> nil then FEvents.OnClick;
  446. end;
  447.  
  448. procedure TDateTimePickerX.CloseUpEvent(Sender: TObject);
  449. begin
  450.   if FEvents <> nil then FEvents.OnCloseUp;
  451. end;
  452.  
  453. procedure TDateTimePickerX.DblClickEvent(Sender: TObject);
  454. begin
  455.   if FEvents <> nil then FEvents.OnDblClick;
  456. end;
  457.  
  458. procedure TDateTimePickerX.DropDownEvent(Sender: TObject);
  459. begin
  460.   if FEvents <> nil then FEvents.OnDropDown;
  461. end;
  462.  
  463. procedure TDateTimePickerX.KeyPressEvent(Sender: TObject; var Key: Char);
  464. var
  465.   TempKey: Smallint;
  466. begin
  467.   TempKey := Smallint(Key);
  468.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  469.   Key := Char(TempKey);
  470. end;
  471.  
  472. procedure TDateTimePickerX.UserInputEvent(Sender: TObject;
  473.   const UserString: String; var DateAndTime: TDateTime;
  474.   var AllowChange: Boolean);
  475. var
  476.   TempDateAndTime: Double;
  477.   TempAllowChange: WordBool;
  478. begin
  479.   TempDateAndTime := Double(DateAndTime);
  480.   TempAllowChange := WordBool(AllowChange);
  481.   if FEvents <> nil then FEvents.OnUserInput(WideString(UserString), TempDateAndTime, TempAllowChange);
  482.   DateAndTime := TDateTime(TempDateAndTime);
  483.   AllowChange := Boolean(TempAllowChange);
  484. end;
  485.  
  486. initialization
  487.   TActiveXControlFactory.Create(
  488.     ComServer,
  489.     TDateTimePickerX,
  490.     TDateTimePicker,
  491.     Class_DateTimePickerX,
  492.     9,
  493.     '{695CDB1B-02E5-11D2-B20D-00C04FA368D4}',
  494.     0,
  495.     tmApartment);
  496. end.
  497.