VCLCommon.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //---------------------------------------------------------------------------
  2. #ifndef VCLCommonH
  3. #define VCLCommonH
  4. //---------------------------------------------------------------------------
  5. #include "Common.h"
  6. #include "Configuration.h"
  7. #include "Exceptions.h"
  8. #include <ComCtrls.hpp>
  9. //---------------------------------------------------------------------------
  10. void __fastcall AdjustListColumnsWidth(TListView * ListView);
  11. void __fastcall EnableControl(TControl* Control, bool Enable);
  12. void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly = true);
  13. void __fastcall InitializeSystemSettings();
  14. void __fastcall FinalizeSystemSettings();
  15. void __fastcall LocalSystemSettings(TCustomForm * Control);
  16. void __fastcall UseSystemSettingsPre(TCustomForm * Control, void ** Settings = NULL);
  17. void __fastcall UseSystemSettingsPost(TCustomForm * Control, void * Settings = NULL);
  18. void __fastcall UseSystemSettings(TCustomForm * Control, void ** Settings = NULL);
  19. void __fastcall ResetSystemSettings(TCustomForm * Control);
  20. void __fastcall RevokeSystemSettings(TCustomForm * Control, void * Settings);
  21. void __fastcall DeleteSystemSettings(TCustomForm * Control, void * Settings);
  22. void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url = L"",
  23. TNotifyEvent OnEnter = NULL);
  24. void __fastcall HintLabel(TStaticText * StaticText, UnicodeString Hint = L"");
  25. void __fastcall HintLabelRestore(TStaticText * StaticText);
  26. void __fastcall HotTrackLabel(TLabel * Label);
  27. void __fastcall FixComboBoxResizeBug(TCustomComboBox * ComboBox);
  28. void __fastcall ShowAsModal(TForm * Form, void *& Storage);
  29. void __fastcall HideAsModal(TForm * Form, void *& Storage);
  30. void __fastcall ReleaseAsModal(TForm * Form, void *& Storage);
  31. TImageList * __fastcall SharedSystemImageList(bool Large);
  32. bool __fastcall SelectDirectory(UnicodeString & Path, const UnicodeString Prompt,
  33. bool PreserveFileName);
  34. enum TListViewCheckAll { caCheck, caUncheck, caToggle };
  35. bool __fastcall ListViewAnyChecked(TListView * ListView, bool Checked = true);
  36. void __fastcall ListViewCheckAll(TListView * ListView,
  37. TListViewCheckAll CheckAll);
  38. void __fastcall ComboAutoSwitchInitialize(TComboBox * ComboBox);
  39. void __fastcall ComboAutoSwitchLoad(TComboBox * ComboBox, TAutoSwitch Value);
  40. TAutoSwitch __fastcall ComboAutoSwitchSave(TComboBox * ComboBox);
  41. void __fastcall CheckBoxAutoSwitchLoad(TCheckBox * CheckBox, TAutoSwitch Value);
  42. TAutoSwitch __fastcall CheckBoxAutoSwitchSave(TCheckBox * CheckBox);
  43. void __fastcall InstallPathWordBreakProc(TWinControl * Control);
  44. void __fastcall SetVerticalControlsOrder(TControl ** ControlsOrder, int Count);
  45. void __fastcall SetHorizontalControlsOrder(TControl ** ControlsOrder, int Count);
  46. void __fastcall MakeNextInTabOrder(TWinControl * Control, TWinControl * After);
  47. void __fastcall CutFormToDesktop(TForm * Form);
  48. void __fastcall UpdateFormPosition(TCustomForm * Form, TPosition Position);
  49. void __fastcall ResizeForm(TCustomForm * Form, int Width, int Height);
  50. TComponent * __fastcall GetFormOwner();
  51. void __fastcall SetCorrectFormParent(TForm * Form);
  52. void __fastcall InvokeHelp(TWinControl * Control);
  53. void __fastcall SetFormIcons(TForm * Form, const UnicodeString & BigIconName,
  54. const UnicodeString & SmallIconName);
  55. Forms::TMonitor * __fastcall FormMonitor(TCustomForm * Form);
  56. int __fastcall GetLastMonitor();
  57. void __fastcall SetLastMonitor(int MonitorNum);
  58. TForm * __fastcall _SafeFormCreate(TMetaClass * FormClass, TComponent * Owner);
  59. template<class FormType>
  60. FormType * __fastcall SafeFormCreate(TComponent * Owner = NULL)
  61. {
  62. return dynamic_cast<FormType *>(_SafeFormCreate(__classid(FormType), Owner));
  63. }
  64. bool __fastcall SupportsSplitButton();
  65. TModalResult __fastcall DefaultResult(TCustomForm * Form);
  66. void __fastcall UseDesktopFont(TControl * Control);
  67. void __fastcall LoadResourceImage(TImage * Image, const UnicodeString & ImageName);
  68. //---------------------------------------------------------------------------
  69. // When exception is left to be handled by Application->OnException
  70. // memory error occurs when clearing the exception for unknown reason.
  71. // (possibly only when exception handling takes too long,
  72. // such as when reconnect is retried)
  73. // deferring call after the catch clause gets rid of the problem.
  74. // on the other hand, not sure if there's some code that actually
  75. // relies on exception leaving the method when we use APPLICATION_EXCEPTION_HACK*
  76. // (such as then timer is called from withing event loop run
  77. // by our code, which we want to break too with the exception).
  78. // Steps to reproduce the problem:
  79. // 1) Connect
  80. // 2) Terminate the server
  81. // 3) Let is try to reconnect once
  82. // 4) Start the server and let it reconnect
  83. // 5) Upon clearing the original terminattion exception from 2)
  84. // the EAccessViolation is thrown
  85. class TApplicationExceptionHackHelper
  86. {
  87. public:
  88. void __fastcall Catch(Exception & E)
  89. {
  90. FSavedException.reset(CloneException(&E));
  91. }
  92. void __fastcall Handle()
  93. {
  94. if (FSavedException.get() != NULL)
  95. {
  96. Application->OnException(Application, FSavedException.get());
  97. Abort();
  98. }
  99. }
  100. private:
  101. std::unique_ptr<Exception> FSavedException;
  102. };
  103. //---------------------------------------------------------------------------
  104. #define APPLICATION_EXCEPTION_HACK_BEGIN \
  105. TApplicationExceptionHackHelper _ExceptionHackHelper; \
  106. try
  107. #define APPLICATION_EXCEPTION_HACK_END \
  108. catch (Exception & E) \
  109. { \
  110. _ExceptionHackHelper.Catch(E); \
  111. } \
  112. _ExceptionHackHelper.Handle();
  113. //---------------------------------------------------------------------------
  114. #endif // VCLCommonH