IdCoreDsnRegister.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.4 12/10/2004 15:36:40 HHariri
  18. Fix so it works with D8 too
  19. Rev 1.3 9/5/2004 2:08:14 PM JPMugaas
  20. Should work in D9 NET.
  21. Rev 1.2 2/3/2004 11:42:52 AM JPMugaas
  22. Fixed for new design.
  23. Rev 1.1 2/1/2004 2:44:20 AM JPMugaas
  24. Bindings editor should be fully functional including IPv6 support.
  25. Rev 1.0 11/13/2002 08:41:18 AM JPMugaas
  26. }
  27. unit IdCoreDsnRegister;
  28. interface
  29. {$I IdCompilerDefines.inc}
  30. uses
  31. {$IFDEF DOTNET}
  32. Borland.Vcl.Design.DesignIntF,
  33. Borland.Vcl.Design.DesignEditors
  34. {$ELSE}
  35. {$IFDEF FPC}
  36. PropEdits,
  37. ComponentEditors
  38. {$ELSE}
  39. {$IFDEF VCL_6_OR_ABOVE}
  40. DesignIntf,
  41. DesignEditors
  42. {$ELSE}
  43. Dsgnintf
  44. {$ENDIF}
  45. {$ENDIF}
  46. {$ENDIF}
  47. ;
  48. type
  49. {$IFDEF FPC}
  50. TIdBaseComponentEditor = class(TDefaultComponentEditor)
  51. {$ELSE}
  52. TIdBaseComponentEditor = class(TDefaultEditor)
  53. {$ENDIF}
  54. public
  55. procedure ExecuteVerb(Index: Integer); override;
  56. function GetVerb(Index: Integer): string; override;
  57. function GetVerbCount: Integer; override;
  58. end;
  59. {$IFDEF FPC}
  60. TIdPropEdBinding = class(TPropertyEditor)
  61. protected
  62. FValue : String;
  63. property Value : String read FValue write FValue;
  64. {$ELSE}
  65. TIdPropEdBinding = class(TClassProperty)
  66. {$ENDIF}
  67. public
  68. procedure Edit; override;
  69. function GetAttributes: TPropertyAttributes; override;
  70. function GetValue: string; override;
  71. procedure SetValue(const Value: string); override;
  72. end;
  73. // Procs
  74. procedure Register;
  75. implementation
  76. uses
  77. Classes,
  78. {$IFDEF WIDGET_WINFORMS}
  79. IdDsnPropEdBindingNET,
  80. IdAboutDotNET,
  81. {$ELSE}
  82. IdDsnPropEdBindingVCL,
  83. IdAboutVCL,
  84. {$ENDIF}
  85. {$IFDEF DCC}
  86. {$IFDEF VCL_2005_OR_ABOVE}
  87. ToolsAPI,
  88. SysUtils,
  89. {$ENDIF}
  90. {$ENDIF}
  91. IdDsnCoreResourceStrings,
  92. IdBaseComponent,
  93. IdComponent,
  94. IdGlobal,
  95. IdStack,
  96. IdSocketHandle;
  97. {
  98. Design Note: It turns out that in DotNET, there are no services file functions and
  99. IdPorts does not work as expected in DotNET. It is probably possible to read the
  100. services file ourselves but that creates some portability problems as the placement
  101. is different in every operating system.
  102. e.g.
  103. Linux and Unix-like systems - /etc
  104. Windows 95, 98, and ME - c:\windows
  105. Windows NT systems - c:\winnt\system32\drivers\etc
  106. Thus, it will undercut whatever benefit we could get with DotNET.
  107. About the best I could think of is to use an edit control because
  108. we can't offer anything from the services file in DotNET.
  109. TODO: Maybe there might be a way to find the location in a more elegant
  110. manner than what I described.
  111. }
  112. type
  113. {$IFDEF WIDGET_WINFORMS}
  114. TIdPropEdBindingEntry = TIdDsnPropEdBindingNET;
  115. {$ELSE}
  116. TIdPropEdBindingEntry = TIdDsnPropEdBindingVCL;
  117. {$ENDIF}
  118. procedure TIdPropEdBinding.Edit;
  119. var
  120. pSockets: TIdSocketHandles;
  121. pEntry: TIdPropEdBindingEntry;
  122. begin
  123. inherited Edit;
  124. {$IFNDEF DOTNET}
  125. pSockets := TIdSocketHandles(
  126. {$IFDEF CPU64}
  127. GetInt64Value
  128. {$ELSE}
  129. GetOrdValue
  130. {$ENDIF}
  131. );
  132. {$ELSE}
  133. pSockets := GetObjValue as TIdSocketHandles;
  134. {$ENDIF}
  135. pEntry := TIdPropEdBindingEntry.Create;
  136. try
  137. pEntry.Caption := TComponent(GetComponent(0)).Name;
  138. pEntry.DefaultPort := pSockets.DefaultPort;
  139. Value := GetListValues(pSockets);
  140. pEntry.SetList(Value);
  141. if pEntry.Execute then
  142. begin
  143. Value := pEntry.GetList;
  144. FillHandleList(Value, pSockets);
  145. end;
  146. finally
  147. pEntry.Free;
  148. end;
  149. end;
  150. function TIdPropEdBinding.GetAttributes: TPropertyAttributes;
  151. begin
  152. Result := inherited GetAttributes + [paDialog];
  153. end;
  154. function TIdPropEdBinding.GetValue: string;
  155. var
  156. pSockets: TIdSocketHandles;
  157. begin
  158. {$IFNDEF DOTNET}
  159. pSockets := TIdSocketHandles(
  160. {$IFDEF CPU64}
  161. GetInt64Value
  162. {$ELSE}
  163. GetOrdValue
  164. {$ENDIF}
  165. );
  166. {$ELSE}
  167. pSockets := GetObjValue as TIdSocketHandles;
  168. {$ENDIF}
  169. Result := GetListValues(pSockets);
  170. end;
  171. procedure TIdPropEdBinding.SetValue(const Value: string);
  172. var
  173. pSockets: TIdSocketHandles;
  174. begin
  175. inherited SetValue(Value);
  176. {$IFNDEF DOTNET}
  177. pSockets := TIdSocketHandles(
  178. {$IFDEF CPU64}
  179. GetInt64Value
  180. {$ELSE}
  181. GetOrdValue
  182. {$ENDIF}
  183. );
  184. {$ELSE}
  185. pSockets := GetObjValue as TIdSocketHandles;
  186. {$ENDIF}
  187. pSockets.BeginUpdate;
  188. try
  189. FillHandleList(Value, pSockets);
  190. finally
  191. pSockets.EndUpdate;
  192. end;
  193. end;
  194. { TIdBaseComponentEditor }
  195. procedure TIdBaseComponentEditor.ExecuteVerb(Index: Integer);
  196. begin
  197. case Index of
  198. 0 : TfrmAbout.ShowDlg;
  199. end;
  200. end;
  201. function TIdBaseComponentEditor.GetVerb(Index: Integer): string;
  202. begin
  203. case Index of
  204. 0: Result := IndyFormat(RSAAboutMenuItemName, [gsIdVersion]);
  205. end;
  206. end;
  207. function TIdBaseComponentEditor.GetVerbCount: Integer;
  208. begin
  209. Result := 1;
  210. end;
  211. procedure Register;
  212. begin
  213. RegisterPropertyEditor(TypeInfo(TIdSocketHandles), nil, '', TIdPropEdBinding); {Do not Localize}
  214. RegisterComponentEditor(TIdBaseComponent, TIdBaseComponentEditor);
  215. end;
  216. {$IFDEF DCC}
  217. {$IFDEF VCL_2005_OR_ABOVE}
  218. var
  219. AboutBoxServices: IOTAAboutBoxServices = nil;
  220. AboutBoxIndex: Integer = -1;
  221. procedure RegisterAboutBox;
  222. begin
  223. if Supports(BorlandIDEServices, IOTAAboutBoxServices, AboutBoxServices) then
  224. begin
  225. AboutBoxIndex := AboutBoxServices.AddPluginInfo(
  226. RSAAboutBoxCompName + ' ' + gsIdVersion,
  227. RSAAboutBoxDescription + sLineBreak + sLineBreak
  228. + RSAAboutBoxCopyright + sLineBreak + sLineBreak
  229. + RSAAboutBoxPleaseVisit + sLineBreak + RSAAboutBoxIndyWebsite,
  230. 0,
  231. False,
  232. RSAAboutBoxLicences,
  233. '');
  234. end;
  235. end;
  236. procedure UnregisterAboutBox;
  237. begin
  238. if (AboutBoxIndex <> -1) and (AboutBoxServices <> nil) then
  239. begin
  240. AboutBoxServices.RemovePluginInfo(AboutBoxIndex);
  241. end;
  242. end;
  243. initialization
  244. RegisterAboutBox;
  245. finalization
  246. UnregisterAboutBox;
  247. {$ENDIF}
  248. {$ENDIF}
  249. end.