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

  1. unit EditImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelC_TLB;
  8.  
  9. type
  10.   TEditX = class(TActiveXControl, IEditX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TEdit;
  14.     FEvents: IEditXEvents;
  15.     procedure ChangeEvent(Sender: TObject);
  16.     procedure ClickEvent(Sender: TObject);
  17.     procedure DblClickEvent(Sender: TObject);
  18.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  19.   protected
  20.     { Protected declarations }
  21.     procedure InitializeControl; override;
  22.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  23.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  24.     function Get_AutoSelect: WordBool; safecall;
  25.     function Get_AutoSize: WordBool; safecall;
  26.     function Get_BorderStyle: TxBorderStyle; safecall;
  27.     function Get_CharCase: TxEditCharCase; safecall;
  28.     function Get_Color: TColor; safecall;
  29.     function Get_Ctl3D: WordBool; safecall;
  30.     function Get_Cursor: Smallint; safecall;
  31.     function Get_DragCursor: Smallint; safecall;
  32.     function Get_DragMode: TxDragMode; safecall;
  33.     function Get_Enabled: WordBool; safecall;
  34.     function Get_Font: Font; safecall;
  35.     function Get_HideSelection: WordBool; safecall;
  36.     function Get_ImeMode: TxImeMode; safecall;
  37.     function Get_ImeName: WideString; safecall;
  38.     function Get_MaxLength: Integer; safecall;
  39.     function Get_Modified: WordBool; safecall;
  40.     function Get_OEMConvert: WordBool; safecall;
  41.     function Get_ParentColor: WordBool; safecall;
  42.     function Get_ParentCtl3D: WordBool; safecall;
  43.     function Get_PasswordChar: Smallint; safecall;
  44.     function Get_ReadOnly: WordBool; safecall;
  45.     function Get_SelLength: Integer; safecall;
  46.     function Get_SelStart: Integer; safecall;
  47.     function Get_SelText: WideString; safecall;
  48.     function Get_Text: WideString; safecall;
  49.     function Get_Visible: WordBool; safecall;
  50.     procedure AboutBox; safecall;
  51.     procedure Clear; safecall;
  52.     procedure ClearSelection; safecall;
  53.     procedure CopyToClipboard; safecall;
  54.     procedure CutToClipboard; safecall;
  55.     procedure PasteFromClipboard; safecall;
  56.     procedure SelectAll; safecall;
  57.     procedure Set_AutoSelect(Value: WordBool); safecall;
  58.     procedure Set_AutoSize(Value: WordBool); safecall;
  59.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  60.     procedure Set_CharCase(Value: TxEditCharCase); safecall;
  61.     procedure Set_Color(Value: TColor); safecall;
  62.     procedure Set_Ctl3D(Value: WordBool); safecall;
  63.     procedure Set_Cursor(Value: Smallint); safecall;
  64.     procedure Set_DragCursor(Value: Smallint); safecall;
  65.     procedure Set_DragMode(Value: TxDragMode); safecall;
  66.     procedure Set_Enabled(Value: WordBool); safecall;
  67.     procedure Set_Font(const Value: Font); safecall;
  68.     procedure Set_HideSelection(Value: WordBool); safecall;
  69.     procedure Set_ImeMode(Value: TxImeMode); safecall;
  70.     procedure Set_ImeName(const Value: WideString); safecall;
  71.     procedure Set_MaxLength(Value: Integer); safecall;
  72.     procedure Set_Modified(Value: WordBool); safecall;
  73.     procedure Set_OEMConvert(Value: WordBool); safecall;
  74.     procedure Set_ParentColor(Value: WordBool); safecall;
  75.     procedure Set_ParentCtl3D(Value: WordBool); safecall;
  76.     procedure Set_PasswordChar(Value: Smallint); safecall;
  77.     procedure Set_ReadOnly(Value: WordBool); safecall;
  78.     procedure Set_SelLength(Value: Integer); safecall;
  79.     procedure Set_SelStart(Value: Integer); safecall;
  80.     procedure Set_SelText(const Value: WideString); safecall;
  81.     procedure Set_Text(const Value: WideString); safecall;
  82.     procedure Set_Visible(Value: WordBool); safecall;
  83.   end;
  84.  
  85. implementation
  86.  
  87. uses About10;
  88.  
  89. { TEditX }
  90.  
  91. procedure TEditX.InitializeControl;
  92. begin
  93.   FDelphiControl := Control as TEdit;
  94.   FDelphiControl.OnChange := ChangeEvent;
  95.   FDelphiControl.OnClick := ClickEvent;
  96.   FDelphiControl.OnDblClick := DblClickEvent;
  97.   FDelphiControl.OnKeyPress := KeyPressEvent;
  98. end;
  99.  
  100. procedure TEditX.EventSinkChanged(const EventSink: IUnknown);
  101. begin
  102.   FEvents := EventSink as IEditXEvents;
  103. end;
  104.  
  105. procedure TEditX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  106. begin
  107.   { Define property pages here.  Property pages are defined by calling
  108.     DefinePropertyPage with the class id of the page.  For example,
  109.       DefinePropertyPage(Class_EditXPage); }
  110. end;
  111.  
  112. function TEditX.Get_AutoSelect: WordBool;
  113. begin
  114.   Result := FDelphiControl.AutoSelect;
  115. end;
  116.  
  117. function TEditX.Get_AutoSize: WordBool;
  118. begin
  119.   Result := FDelphiControl.AutoSize;
  120. end;
  121.  
  122. function TEditX.Get_BorderStyle: TxBorderStyle;
  123. begin
  124.   Result := Ord(FDelphiControl.BorderStyle);
  125. end;
  126.  
  127. function TEditX.Get_CharCase: TxEditCharCase;
  128. begin
  129.   Result := Ord(FDelphiControl.CharCase);
  130. end;
  131.  
  132. function TEditX.Get_Color: TColor;
  133. begin
  134.   Result := FDelphiControl.Color;
  135. end;
  136.  
  137. function TEditX.Get_Ctl3D: WordBool;
  138. begin
  139.   Result := FDelphiControl.Ctl3D;
  140. end;
  141.  
  142. function TEditX.Get_Cursor: Smallint;
  143. begin
  144.   Result := Smallint(FDelphiControl.Cursor);
  145. end;
  146.  
  147. function TEditX.Get_DragCursor: Smallint;
  148. begin
  149.   Result := Smallint(FDelphiControl.DragCursor);
  150. end;
  151.  
  152. function TEditX.Get_DragMode: TxDragMode;
  153. begin
  154.   Result := Ord(FDelphiControl.DragMode);
  155. end;
  156.  
  157. function TEditX.Get_Enabled: WordBool;
  158. begin
  159.   Result := FDelphiControl.Enabled;
  160. end;
  161.  
  162. function TEditX.Get_Font: Font;
  163. begin
  164.   GetOleFont(FDelphiControl.Font, Result);
  165. end;
  166.  
  167. function TEditX.Get_HideSelection: WordBool;
  168. begin
  169.   Result := FDelphiControl.HideSelection;
  170. end;
  171.  
  172. function TEditX.Get_ImeMode: TxImeMode;
  173. begin
  174.   Result := Ord(FDelphiControl.ImeMode);
  175. end;
  176.  
  177. function TEditX.Get_ImeName: WideString;
  178. begin
  179.   Result := WideString(FDelphiControl.ImeName);
  180. end;
  181.  
  182. function TEditX.Get_MaxLength: Integer;
  183. begin
  184.   Result := FDelphiControl.MaxLength;
  185. end;
  186.  
  187. function TEditX.Get_Modified: WordBool;
  188. begin
  189.   Result := FDelphiControl.Modified;
  190. end;
  191.  
  192. function TEditX.Get_OEMConvert: WordBool;
  193. begin
  194.   Result := FDelphiControl.OEMConvert;
  195. end;
  196.  
  197. function TEditX.Get_ParentColor: WordBool;
  198. begin
  199.   Result := FDelphiControl.ParentColor;
  200. end;
  201.  
  202. function TEditX.Get_ParentCtl3D: WordBool;
  203. begin
  204.   Result := FDelphiControl.ParentCtl3D;
  205. end;
  206.  
  207. function TEditX.Get_PasswordChar: Smallint;
  208. begin
  209.   Result := Smallint(FDelphiControl.PasswordChar);
  210. end;
  211.  
  212. function TEditX.Get_ReadOnly: WordBool;
  213. begin
  214.   Result := FDelphiControl.ReadOnly;
  215. end;
  216.  
  217. function TEditX.Get_SelLength: Integer;
  218. begin
  219.   Result := FDelphiControl.SelLength;
  220. end;
  221.  
  222. function TEditX.Get_SelStart: Integer;
  223. begin
  224.   Result := FDelphiControl.SelStart;
  225. end;
  226.  
  227. function TEditX.Get_SelText: WideString;
  228. begin
  229.   Result := WideString(FDelphiControl.SelText);
  230. end;
  231.  
  232. function TEditX.Get_Text: WideString;
  233. begin
  234.   Result := WideString(FDelphiControl.Text);
  235. end;
  236.  
  237. function TEditX.Get_Visible: WordBool;
  238. begin
  239.   Result := FDelphiControl.Visible;
  240. end;
  241.  
  242. procedure TEditX.AboutBox;
  243. begin
  244.   ShowEditXAbout;
  245. end;
  246.  
  247. procedure TEditX.Clear;
  248. begin
  249.  
  250. end;
  251.  
  252. procedure TEditX.ClearSelection;
  253. begin
  254.  
  255. end;
  256.  
  257. procedure TEditX.CopyToClipboard;
  258. begin
  259.  
  260. end;
  261.  
  262. procedure TEditX.CutToClipboard;
  263. begin
  264.  
  265. end;
  266.  
  267. procedure TEditX.PasteFromClipboard;
  268. begin
  269.  
  270. end;
  271.  
  272. procedure TEditX.SelectAll;
  273. begin
  274.  
  275. end;
  276.  
  277. procedure TEditX.Set_AutoSelect(Value: WordBool);
  278. begin
  279.   FDelphiControl.AutoSelect := Value;
  280. end;
  281.  
  282. procedure TEditX.Set_AutoSize(Value: WordBool);
  283. begin
  284.   FDelphiControl.AutoSize := Value;
  285. end;
  286.  
  287. procedure TEditX.Set_BorderStyle(Value: TxBorderStyle);
  288. begin
  289.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  290. end;
  291.  
  292. procedure TEditX.Set_CharCase(Value: TxEditCharCase);
  293. begin
  294.   FDelphiControl.CharCase := TEditCharCase(Value);
  295. end;
  296.  
  297. procedure TEditX.Set_Color(Value: TColor);
  298. begin
  299.   FDelphiControl.Color := Value;
  300. end;
  301.  
  302. procedure TEditX.Set_Ctl3D(Value: WordBool);
  303. begin
  304.   FDelphiControl.Ctl3D := Value;
  305. end;
  306.  
  307. procedure TEditX.Set_Cursor(Value: Smallint);
  308. begin
  309.   FDelphiControl.Cursor := TCursor(Value);
  310. end;
  311.  
  312. procedure TEditX.Set_DragCursor(Value: Smallint);
  313. begin
  314.   FDelphiControl.DragCursor := TCursor(Value);
  315. end;
  316.  
  317. procedure TEditX.Set_DragMode(Value: TxDragMode);
  318. begin
  319.   FDelphiControl.DragMode := TDragMode(Value);
  320. end;
  321.  
  322. procedure TEditX.Set_Enabled(Value: WordBool);
  323. begin
  324.   FDelphiControl.Enabled := Value;
  325. end;
  326.  
  327. procedure TEditX.Set_Font(const Value: Font);
  328. begin
  329.   SetOleFont(FDelphiControl.Font, Value);
  330. end;
  331.  
  332. procedure TEditX.Set_HideSelection(Value: WordBool);
  333. begin
  334.   FDelphiControl.HideSelection := Value;
  335. end;
  336.  
  337. procedure TEditX.Set_ImeMode(Value: TxImeMode);
  338. begin
  339.   FDelphiControl.ImeMode := TImeMode(Value);
  340. end;
  341.  
  342. procedure TEditX.Set_ImeName(const Value: WideString);
  343. begin
  344.   FDelphiControl.ImeName := TImeName(Value);
  345. end;
  346.  
  347. procedure TEditX.Set_MaxLength(Value: Integer);
  348. begin
  349.   FDelphiControl.MaxLength := Value;
  350. end;
  351.  
  352. procedure TEditX.Set_Modified(Value: WordBool);
  353. begin
  354.   FDelphiControl.Modified := Value;
  355. end;
  356.  
  357. procedure TEditX.Set_OEMConvert(Value: WordBool);
  358. begin
  359.   FDelphiControl.OEMConvert := Value;
  360. end;
  361.  
  362. procedure TEditX.Set_ParentColor(Value: WordBool);
  363. begin
  364.   FDelphiControl.ParentColor := Value;
  365. end;
  366.  
  367. procedure TEditX.Set_ParentCtl3D(Value: WordBool);
  368. begin
  369.   FDelphiControl.ParentCtl3D := Value;
  370. end;
  371.  
  372. procedure TEditX.Set_PasswordChar(Value: Smallint);
  373. begin
  374.   FDelphiControl.PasswordChar := Char(Value);
  375. end;
  376.  
  377. procedure TEditX.Set_ReadOnly(Value: WordBool);
  378. begin
  379.   FDelphiControl.ReadOnly := Value;
  380. end;
  381.  
  382. procedure TEditX.Set_SelLength(Value: Integer);
  383. begin
  384.   FDelphiControl.SelLength := Value;
  385. end;
  386.  
  387. procedure TEditX.Set_SelStart(Value: Integer);
  388. begin
  389.   FDelphiControl.SelStart := Value;
  390. end;
  391.  
  392. procedure TEditX.Set_SelText(const Value: WideString);
  393. begin
  394.   FDelphiControl.SelText := String(Value);
  395. end;
  396.  
  397. procedure TEditX.Set_Text(const Value: WideString);
  398. begin
  399.   FDelphiControl.Text := TCaption(Value);
  400. end;
  401.  
  402. procedure TEditX.Set_Visible(Value: WordBool);
  403. begin
  404.   FDelphiControl.Visible := Value;
  405. end;
  406.  
  407. procedure TEditX.ChangeEvent(Sender: TObject);
  408. begin
  409.   if FEvents <> nil then FEvents.OnChange;
  410. end;
  411.  
  412. procedure TEditX.ClickEvent(Sender: TObject);
  413. begin
  414.   if FEvents <> nil then FEvents.OnClick;
  415. end;
  416.  
  417. procedure TEditX.DblClickEvent(Sender: TObject);
  418. begin
  419.   if FEvents <> nil then FEvents.OnDblClick;
  420. end;
  421.  
  422. procedure TEditX.KeyPressEvent(Sender: TObject; var Key: Char);
  423. var
  424.   TempKey: Smallint;
  425. begin
  426.   TempKey := Smallint(Key);
  427.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  428.   Key := Char(TempKey);
  429. end;
  430.  
  431. initialization
  432.   TActiveXControlFactory.Create(
  433.     ComServer,
  434.     TEditX,
  435.     TEdit,
  436.     Class_EditX,
  437.     10,
  438.     '{FA7B8374-9ED7-11D0-AA40-444553540000}',
  439.     0);
  440. end.
  441.