Implementing VirtualTreeView TVTDefaultAccessibleProvider in C++ Builder

时光总嘲笑我的痴心妄想 提交于 2020-02-25 23:06:28

问题


When using VirtualStringTree to add accessibility support it is required to include the unit VirtualTrees.Accessibility in the uses section. This works in Delphi.

The equivalent of this in C++ Builder would be to include the #include "VirtualTrees.Accessibility.hpp". But including the include file doesn't have any effect.

I've traced the problem to the VirtualTrees.Accessibility.pas file and it executes a few lines of code to register the default accessibility provider in Delphi while this code is absent from the hpp file. So including the hpp does include the class but not the code which registers the provider.

The code in question (at the end of VirtualTrees.Accessibility.pas is this):

var
  DefaultAccessibleProvider: TVTDefaultAccessibleProvider;
  DefaultAccessibleItemProvider: TVTDefaultAccessibleItemProvider;
  MultiColumnAccessibleProvider: TVTMultiColumnAccessibleItemProvider;

initialization
  if DefaultAccessibleProvider = nil then
  begin
    DefaultAccessibleProvider := TVTDefaultAccessibleProvider.Create;
    GetAccessibilityFactory.RegisterAccessibleProvider(DefaultAccessibleProvider);
  end;
  if DefaultAccessibleItemProvider = nil then
  begin
    DefaultAccessibleItemProvider := TVTDefaultAccessibleItemProvider.Create;
    GetAccessibilityFactory.RegisterAccessibleProvider(DefaultAccessibleItemProvider);
  end;
  if MultiColumnAccessibleProvider = nil then
  begin
    MultiColumnAccessibleProvider := TVTMultiColumnAccessibleItemProvider.Create;
    GetAccessibilityFactory.RegisterAccessibleProvider(MultiColumnAccessibleProvider);
  end;
finalization
  GetAccessibilityFactory.UnRegisterAccessibleProvider(MultiColumnAccessibleProvider);
  MultiColumnAccessibleProvider := nil;
  GetAccessibilityFactory.UnRegisterAccessibleProvider(DefaultAccessibleItemProvider);
  DefaultAccessibleItemProvider := nil;
  GetAccessibilityFactory.UnRegisterAccessibleProvider(DefaultAccessibleProvider);
  DefaultAccessibleProvider := nil;

end.

My question - how do I translate or use the above so I can have accessibility support from C++ Builder as well after including the VirtualTrees.Accessibility.hpp file? A translation of the above into C++ would be very appreciated.


回答1:


Based on research from this link and answer by Remy Lebeau:

The initialization part is not called

And the opened issue on VirtualTree GitHub:

https://github.com/Virtual-TreeView/Virtual-TreeView/issues/951

I am sharing a solution here, how this might be achieved by either one of the following:

Method A

By calling:

TVirtualTreeAccessibility::RegisterDefaultAccessibleProviders();

somewhere in the cpp file, as suggested by Joachim Marder

Method B

By adding:

#pragma link "VirtualTrees.Accessibility"

in the cpp source file

Method C

By adding something like:

{$HPPEMIT '#pragma link "VirtualTrees.Accessibility"'}

in the VirtualTrees.Accessibility.pas source code



来源:https://stackoverflow.com/questions/60114996/implementing-virtualtreeview-tvtdefaultaccessibleprovider-in-c-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!