3

The suggested other question (Creating Accessible UI components in Delphi) solves this problem, please look there if you are searching for a solution.

I want to do automated UI-Testing in a VCL-Application created with Delphi. I tried various tools, like the Assistant for coded UI-Testing in Visual Studio or "AutoIt", but I always had an annoying problem: Some controls simply dont have a name attached to them, which could be extracted via this tools. I've tried so many different Tools, also WinSpy just to see if the property is THERE, and it isn't.

Here a little example:

Unit.pas:

type
TForm1 = class(TForm)
  Edit1: TEdit;
  Bt1: TButton;
end;

unit.dfm:

object Form1: TForm1
  ...
  object Edit1: TEdit
    Left = 8
    Top = 48
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'This is a Edit named Edit1'
  end
  object Bt1: TButton
    Left = 8
    Top = 8
    Width = 121
    Height = 25
    Caption = 'This is a button named Bt1'
    TabOrder = 1
  end
end

enter image description here

My problem is that I can't identify the controls i want to check or modify. Does someone have an idea why the names are missing on some components, and how I can change this?

Edit: Of course i have assigned names at design time, the problem is that they get lost somehow. I also tried to turn off opimization, but it didnt change anything.

I'm using Embarcadero RAD Studio XE2

Community
  • 1
  • 1
Florian Koch
  • 1,372
  • 1
  • 30
  • 49
  • Err, e.g. because you've created them dynamically and didn't assign a name ? Or, because you've deleted their names at design time ? – TLama Feb 19 '14 at 08:00
  • @TLama no, I created them at DesignTime and their names are there, i acces them via the names in Code. But when looking at Runtime, there are no names – Florian Koch Feb 19 '14 at 08:02
  • You can make a form with name-less components. What you're describing is weird. So, the names are stored in the DFM file, streamed back to the IDE, but not compiled to the output binary. Hmm... Could you include your Delphi version tag to your question, please ? – TLama Feb 19 '14 at 08:16
  • 2
    The compile/design-time name of a component is unrelated to the name that this question is about, isn't it? The name of a component is only used for identifying the component from within the application, not from other applications. –  Feb 19 '14 at 08:24
  • @DavidHeffernan sadly there is no Code i could provide, because it isnt related to this. I can try to show the problem via a screenshot – Florian Koch Feb 19 '14 at 08:25
  • You wrote a program with no code? Really? It's hard to help if you won't let us help you. – David Heffernan Feb 19 '14 at 08:27
  • sorry David, but there is really no code to show i just throw two Controls on a standard form and have my problem – Florian Koch Feb 19 '14 at 08:34
  • @hvd This seems to be the problem, yes. I just need a way to identify my controls, so for me it is not important that the names stay the same as before. I know that Buttons for example get their caption as name, but Edits get nothing and i need a way to solve this problem... – Florian Koch Feb 19 '14 at 08:37
  • Thank you. I'd have expected the name of the control to be it's window text. So only empty edit controls would be nameless. Is that not so? Are you using MSAA or UIAutomation? – David Heffernan Feb 19 '14 at 08:59
  • I think I use MSAA, because this is displayed in the properties of the control, but i don't really know. And the name of TEdit stays empty, even if there is text inside. But even if it would belike this, it wouldnt help me because I mostly have to fill empty edits in the test cases and check their value again after doing some operations. – Florian Koch Feb 19 '14 at 09:06
  • I think the VCL authors are pretty lame here. They could have got their standard controls to advertise names to automation. It's easy to do. I don't have the details to hand. When I get to a computer I'll try to help but likely somebody else will do so sooner. – David Heffernan Feb 19 '14 at 09:08
  • If the component has no printed name property in the dfm, derive the name from the object text line: `object Edit1: TEdit`. – LU RD Feb 19 '14 at 09:14
  • If there is a way too implement this in my own components this would be great, because in the real application there are mostly my own derivations of the components so i could easily get names in the whole application. I already went in the vcl sources and searched how this is done, but it didnt find anything and thought going here to ask would be better (: I didnt work directly with WinForms till now, so I didnt even have a real idea of what i have to look for in the vcl... – Florian Koch Feb 19 '14 at 09:14
  • @LU RD This is the only occurance of the name as far as I know. Sorry but I think you misunderstood my problem. At designtime i have no problems, i want to identify my components at runtime via an external program. – Florian Koch Feb 19 '14 at 09:16
  • Ok, I think we are there now. Remy's excellent answer at the other question will solve your problem. – David Heffernan Feb 19 '14 at 09:17
  • ok thx I'm reading it now – Florian Koch Feb 19 '14 at 09:18
  • Ok, this is solved, a big thanks to you David for finding this, I already searched the web for soem time else I wouldnt have asked here. Seems as if I was missing the right keywords. I'll post the link to the other question as solution – Florian Koch Feb 19 '14 at 09:21
  • Really, this reputation system kinda sucks... Cant even answer my own question now, I have to wait 8 hrs – Florian Koch Feb 19 '14 at 09:23
  • Doesn't matter. The question is on the way to being closed as a duplicate. Which is fine. That will then link the two questions together for future visitors. – David Heffernan Feb 19 '14 at 09:32
  • Oh ok, didnt know this is possible. – Florian Koch Feb 19 '14 at 09:34
  • 1
    But it exactly solves the problem, and in this question there are no others comments which will help out with this problem. IMO this questionb can be closed, because my problem is solved – Florian Koch Feb 19 '14 at 09:47
  • 1
    @JanDoggen The questions should be fixed then so that they meet that exacting standard. The intent of both questions is identical. *Why do `TEdit` controls not have names defined in MSAA, and how do I remedy that?* – David Heffernan Feb 19 '14 at 09:47

0 Answers0