How to set the Accessible Name associated with a TEdit control?
Asked Answered
V

1

17

If a user is using a screen reader (e.g. Microsoft Narrator), and their focus enters a text box:

enter image description here

All they hear is:

Editing text

Meanwhile in accessible applications,

  • such as Microsoft File Explorer
  • Microsoft Word
  • Microsoft Excel
  • Microsoft Outlook

the accessibility system is able to get the control's "Accessible Name":

enter image description here

Batch separator. Editing text

This works though the window implementing the IAccessible interface. It obtains a window's implementation of IAccessible by sending the hWnd the WM_GETOBJECT message. Applications never send this message though:

Sent by both Microsoft Active Accessibility and Microsoft UI Automation to obtain information about an accessible object contained in a server application.

Applications never send this message directly. Microsoft Active Accessibility sends this message in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow.

But we can handle the message, and return an IAccessible interface to the caller:

case Message.Msg of
WM_GETOBJECT: 
   begin
      if DWORD(Message.LParam) = OBJID_CLIENT then
         Message.Result := LResultFromObject(IAccessible, Message.WParam, FAccessible);
   end;
end;

In the .NET world, their wrapper around an Edit control, exposes a way to set the accessible name of an TextBox using the Control.AccessibleName property:

Control.AccessibleName Property

Gets or sets the name of the control used by accessibility client applications.

public string AccessibleName { get; set; }

I don't know how the underlying Microsoft Edit control exposes accessibility features. I couldn't find any reference to IAccessible in the VCL except for TCustomActionMenuBar.

How does the VCL expose accessibility features?

How do i set the Accessible Name associated with a TEdit control?

How do i set the Accessible Name associated with an Edit control?

Bonus Chatter

The name of an accessible item is returned through the read-only IAccessible.accName property.

Property  Access Type  Description
--------  -----------  ----------------------------------------------------------
accName   Read-only    The name of the object. All objects support this property.
                       See get_accName.

Bonus Reading

Vallecula answered 28/3, 2018 at 15:6 Comment(1)
Implement IAccessible interface by yourself (the Accessible Name you return in its Get_accName method).Knisley
A
9

How does the VCL expose accessibility features?

It doesn't, at all.

If you want this feature, you have to manually implement everything related to IAccessible yourself in your own code, and then subclass your VCL controls to respond to the WM_GETOBJECT message, just like you showed in your question.

For example:

Creating Accessible UI components in Delphi

Altheta answered 28/3, 2018 at 16:10 Comment(1)
AFAIK, currently only TActionBar implements this feature.Insolate

© 2022 - 2024 — McMap. All rights reserved.