Jump to content
Oboba

UIAutomation in Delphi 13

Recommended Posts

The changelog for the new Delphi version says: "VCL includes, for the first time, an integration of the UIAutomation Microsoft interfaces, which can be used to support accessibility and to build automatic UI testing." - but there seems to be no real examples of how to use it or any ready support in the existing controls.

 

Seems that there added TUIAutomationCustomControlProvider class and headers from Winapi. How can this be used to improve accessibility of a program created in Delphi?

  • Like 2

Share this post


Link to post

I have another question: is it possible to disable this new feature altogether to get rid of the new dependency on uiautomationcore.dll, which prevents .exe files from running on older versions of Windows, like XP and 2000?

Edited by zed

Share this post


Link to post

Could UIAutomation increase the possibility of malicious software interfacing more easily with an application to cause problems?

 

Share this post


Link to post
25 minutes ago, shineworld said:

Could UIAutomation increase the possibility of malicious software interfacing more easily with an application to cause problems?

 

I don't thnk so, at least until you create a provider.
For now, Delphi creates applications with a nil UIA provider (I tested some applications of mine),  I don't think there are any problems.
But if you manually create a provider, it's configured on the server, and it's possible that you can interact with it from the outside. I don't know to what extent.

I think we should wait until more explanation will come from Embarcadero or from other experts.

Share this post


Link to post
7 minutes ago, DelphiUdIT said:

For now, Delphi creates applications with a nil UIA provider (I tested some applications of mine),  I don't think there are any problems.

Indeed.   At the moment all we got is some scaffolding.  Had Embarcadero declared the UIAutomation functions as delayed no dll would be loaded.   Maybe you could submit an issue to that effect.  But you could try to do that with your project.  Edit Winapi.UIAutomation to add the delayed attribute and include it in your project (not tested).

Edited by pyscripter
  • Like 1

Share this post


Link to post
20 minutes ago, pyscripter said:

Indeed.   At the moment all we got is some scaffolding.  Had Embarcadero declared the UIAutomation functions as delayed no dll would be loaded.   Maybe you could submit an issue to that effect.  But you could try to do that with your project.   Edit Winapi.UIAutomation to add the delayed attribute and include it in your project (not tested).

It works. Adding the delayed attribute prevents the DLL from loading.

By now, since in the future EMB can always call it to initialize something ....

Share this post


Link to post
1 hour ago, zed said:

I have another question: is it possible to disable this new feature altogether to get rid of the new dependency on uiautomationcore.dll, which prevents .exe files from running on older versions of Windows, like XP and 2000?

Except compiling in a previous Delphi release, I don't think it's possible.

 

The supported Windows target are :

Windows 11
Windows 10
Windows Server 2025
Windows Server 2022

Delphi XE5 is the latest platform officially compatible with Windows XP.

 

https://docwiki.embarcadero.com/PlatformStatus/en/Main_Page

  • Thanks 1

Share this post


Link to post
5 hours ago, Patrick PREMARTIN said:

Except compiling in a previous Delphi release, I don't think it's possible.

It is possible with some additional tweaking.  You can go into the compiler's linker options and set the PE header OS Version and SubSystem Version fields to 5.0 for Win2K or 5.1 for XP.  Also, if you use the System.Threading unit then make a copy of it, modify it to call GetTickCount() instead of GetTickCount64() on pre-Vista systems, and then add the copy to your project.

Edited by Remy Lebeau
  • Like 3

Share this post


Link to post
9 hours ago, zed said:

I have another question: is it possible to disable this new feature altogether to get rid of the new dependency on uiautomationcore.dll, which prevents .exe files from running on older versions of Windows, like XP and 2000?

I don't think so, unless you want to modify RTL sources. Vcl.Controls uses WinApi.UIAutomation unit which has static imports from UIAutomationCore.dll. 

 

8 hours ago, pyscripter said:

Have a look at SynEdit/Source/SynAccessibility.pas at master · pyscripter/SynEdit to see how UI.Automation can be used for accessibility support.  SynEdit was one of the first Delphi controls to support UI Automation for this purpose.

Thank you, will have a look at it.

Share this post


Link to post
11 hours ago, Oboba said:

I don't think so, unless you want to modify RTL sources. Vcl.Controls uses WinApi.UIAutomation unit which has static imports from UIAutomationCore.dll. 

 

Thank you, will have a look at it.

Hmm, as a last resort solution, you could create a fake UIAutomationCore.dll for Windows 2000 computers and save it to your application's folder...

Edited by Vandrovnik

Share this post


Link to post
7 hours ago, Vandrovnik said:

Hmm, as a last resort solution, you could create a fake UIAutomationCore.dll for Windows 2000 computers and save it to your application's folder...

Like I wrote (suggestion from @pyscripter) simply add 'delayed' in the UIAuotmation unit.

Share this post


Link to post

This new Winapi.UIAutomation unit has IAccesible declared, in addition, it has always been declared in Winapi.oleacc unit. And those declarations are different, e.g., the Get_accName method:

// oleacc
function Get_accName(varChild: OleVariant; out pszName: WideString): HResult; stdcall;

//UIAutomation
function get_accName(varChild: OleVariant; out pszName: PChar): HRESULT; stdcall;

- if UIAutomation unit is used in the existing unit where a class implements IAccessible, it no longer compiles.


 

Also ISelectionProvider seems to be off, its GetSelection is declared like this

function GetSelection(out pRetVal: SAFEARRAY): HRESULT; stdcall;

while it should be 

function GetSelection(out pRetVal: PSAFEARRAY): HRESULT; stdcall;

to match the WinApi declaration. And it does throw Access Violation if the Delphi's ISelectionProvider declaration is used. 

 

It's either I'm totally wrong about something, or UIAutomation unit needs some more work.

Edited by Oboba

Share this post


Link to post

This new Winapi.UIAutomation unit has IAccesible declared, in addition, it has always been declared in Winapi.oleacc unit. And those declarations are different, e.g., the Get_accName method:

// oleacc
function Get_accName(varChild: OleVariant; out pszName: WideString): HResult; stdcall;

//UIAutomation
function get_accName(varChild: OleVariant; out pszName: PChar): HRESULT; stdcall;

- if UIAutomation unit is used in the existing unit where a class implements IAccessible, it no longer compiles.


 

Also ISelectionProvider seems to be off, it GetSelection is declared like this

function GetSelection(out pRetVal: SAFEARRAY): HRESULT; stdcall;

while it should be 

function GetSelection(out pRetVal: PSAFEARRAY): HRESULT; stdcall;

to match the WinApi declaration. And it does throw Access Violation if the Delphi's ISelectionProvider declaration is used. 

 

It's either I'm totally wrong about something, or UIAutomation unit needs some more work

Share this post


Link to post
38 minutes ago, Oboba said:

Also ISelectionProvider seems to be off, it GetSelection is declared like this

Indeed.   See also my own translation: https://github.com/pyscripter/SynEdit/blob/27b5d713b4806ccbf38412cd138d8ee7d4ccc499/Source/SynAccessibility.pas#L220

 

The weird thing is that GetIt includes the "Windows API from WinMD" package that has correct translations of the Automation API and many others.  Why Embarcadero did not use these translations escapes me.

 

Please submit a bug report.

  • Like 3

Share this post


Link to post
1 hour ago, Oboba said:

This new Winapi.UIAutomation unit has IAccesible declared, in addition, it has always been declared in Winapi.oleacc unit. And those declarations are different, e.g., the Get_accName method

Hmm, I don't think they should have re-declared IAccessible. They should have had Winapi.UIAutomation use Winapi.oleacc instead.  Even the SDK uiautomationcore.h header doesn't redeclare IAccessible.  The new IAccessibleEx inherits from the IAccessible in oleacc.h.

1 hour ago, Oboba said:

Also ISelectionProvider seems to be off, it GetSelection is declared like this


function GetSelection(out pRetVal: SAFEARRAY): HRESULT; stdcall;

while it should be 


function GetSelection(out pRetVal: PSAFEARRAY): HRESULT; stdcall;

to match the WinApi declaration.

Agreed.

1 hour ago, Oboba said:

It's either I'm totally wrong about something, or UIAutomation unit needs some more work

I would say it needs more work.

  • Like 1

Share this post


Link to post

About UIAutomationCore.dll, ChatGPT says the following:

 

"Windows XP and earlier versions do not include this file by default. They relied mainly on MSAA. However, UIAutomation could be installed on Windows XP by installing the .NET Framework 3.0/3.5 (which backported parts of the API and the DLL)".

Share this post


Link to post
On 9/28/2025 at 1:08 AM, pyscripter said:

Please submit a bug report.

I did.

 

On 9/28/2025 at 2:17 AM, Remy Lebeau said:

I don't think they should have re-declared IAccessible. They should have had Winapi.UIAutomation use Winapi.oleacc instead.

I also think so, is there any adequate reason why they didn't do so? 

Share this post


Link to post

Hello,

Has someone made tickets for Emba of these issues in this discussion. If/will so so, links please.

-tee-

Share this post


Link to post

I must admit that I miss the old "voting on bugs" feature of the bug portal.   At least it felt like I had some kind of voice (even if it wasn't exactly a roar lol.)  Is there a bug report or feature request to add "delayed"?   Would it make sense to add the "delayed" request as a bug report, a feature request, or just as a comment on one of the other UIAutomation entries?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×