views:

211

answers:

3

Hello, is possible via the Windows API's to enumerate and iterate the VCL controls on a form (TForm) belonging to a external Win32 application written in C ++ Builder or Delphi.

Bye.

+6  A: 

No. First of all, consider that the Windows API has no idea what the "VCL" is. It doesn't know "TButton" or "TStringGrid," and it certainly doesn't know "TImage" or "TLabel," which don't even have window handles.

You could use EnumChildWindows to get handles to the windowed controls. You could look at their class names to determine that they came from "TButton" or "TStringGrid," but even then, you would not have access to any object-related facilities. You wouldn't have an object reference, and so you could not read any properties or call any methods.

TestComplete, from Automated QA, offers access to a program's forms and classes from an external program, which sounds like what you might be trying to do. It works by having a unit that you include in the Delphi program, and that unit essentially provides a back door for the TestComplete program to use to query the program's internals. That requires cooperation from the application developer; you can't sic TestComplete on an arbitrary program.

Rob Kennedy
here is a useful utility http://catch22.net/software/winspy which will allow you easily browse the data that is returned from the windows API calls over a window/control.
skamradt
A: 

You could look at the DFMs, which are stored as resources in the executable.

Anders Ohlsson put together a VCL Scanner application that does just this a while ago. The source code is also available.

Bruce McGee
A: 

Up until Delphi 2006, you could use the vcltest3.dll for this. But now you have to go the way Rob Kennedy proposes.

Jeroen Pluimers