How to get the property list and values of a control within a third-party Delphi application? - delphi

I'd like to get information about a third party application's controls such as a list of its properties and their values: something like RTTI information but for a third-party Delphi application.
I see that this is possible. For example TestComplete has the ObjectSpy window which can give many useful information about the control, including RTTI information. How can this be done ?
Edit: To explain why I'm investigating this issue... I'm a registered user of TestComplete/TestExecute and I do like... most of it. I can get over the minor things but the one major problem for me is their license verification system which requires me to have a physical computer (not a virtual machine) always on just for the sake of running a license server so that TestExecute can run at night. As I have basic testing needs (compare screenshots and check basic Delphi component's properties) I wondered how hard it would be to make my own private very simple "TestExecute-like" application.

To go further, I suggest you these relevant resources found here on SO
Writing a very basic debugger (The accepted answer along with its comment thread are all valuable).
Is it possible to access memory from an application to another ? How? (Excerpt from the accepted answer: It is possible. Just use the Windows API functions WriteProcessMemory/ReadProcessMemory. Pass in the handle of the process and the pointer to the data).
Search the memory of another process (The excellent accepted answer also forwards to another valuable resource delphi-code-coverage by Christer Fahlgren and Nick Ring).
StackWalk of other process in delphi? (Check Barry Kelly's answer !!!, the same for the one from the AsmProfiler author !!!).
I strongly suggest you to port to Delphi this c++ project entitled Get Process Info with NtQueryInformationProcess: A hands on experience on using ReadProcessMemory to access the CommandLine used to launch another process.
Last Edit:
NtQuerySystemInformation Delphi Example.
RRUZ's answer to Delphi - get what files are opened by an application as suggested by LU RD.

When we want to take another application which is compiled with debug information and get stuff out of it at runtime, what we are dealing with is the problem of "how to write my own custom debugger/profiler/automated-test kernel".
TestComplete and other AutomatedQA programs contain a Debugger and Profiler Kernel which can start up, run and remotely control apps, and parse their Debug information in several formats, including the TurboDebugger TD32 information attached to these executables. Their profiling kernel also can see each object as it is created, and can iterate the RTTI-like debug information to determine that an object that was created is of a particular class type, and then see what properties exist in that object.
Now, TestComplete adds on top of the AQTime-level of stuff, the ability to introspect Window handles, and intuit from Window Handles, the Delphi class Names that are behind it. However, it's much easier for you (or me) to write a program which can tell you that the mouse is over a window handle that belongs to a TPanel, than to know which version of Delphi created that particular executable, what version of TPanel that is, then, and what properties it would contain, and to read those values back from a running program, which requires that you implement your own "debugger engine". I am not aware of any open source applications that you could even use to get a start writing your own debugger, and you certainly can't use the ones that are inside AQTime/TestComplete, or the one inside Delphi itself, in your own apps.
I could not write you a sample program to do this, but even if I could, it would require a lot of third-party library support. To see the window classes for a window handle which your mouse is over, look for how to implement something like the MS Spy++ utility.
An easy case is if your mouse is mousing over a window inside your own application. For that, see this about.com link, which simply uses RTTI.

Related

DragDrop between two FMX applications

Hi I need to drag an image from one application to another. Both are Delphi FMX applications. I was successful in doing it within one application but now need to transfer between two separate applications, ie no memory sharing. I would be happy to save all info into a file and transfer the file name in the operation. I do detect the dragover event in the receiving application but the data property is nil and I don't know how to populate it with a useful value.
I am using Windows 10, Delphi XE10.3
Any example, explanation will be helpful
Thank you
Did you find an answer?
I am trying something similar. Andreas is right about proper OLE, but it will be a lot of work to implement in FireMonkey.
The problem is that FireMonkey, on Windows, only interprets external drags of files (by their name and path) or unicode text. It can accept other external drags, but extracts no information so it is useless.
Look in FMX.Platform.Win.
TWinFropTarget.GetDataObject() is the culprit.
PlatformWin.FDragAndDropActive is true for internal drags and false for external.
External drags of CF_HDROP (filenames) and CF_UNICODETEXT (unicode text) only are interpreted.
To implement yourself steps would be
Roll your own IDropTarget.
Register it with Windows. See TPlatformWin.CreateWindow(), call to RegisterDragDrop()
Create a mechanism for freeing it, which is all TWinWindowHandle.FWinDropTarget does, but FWinDropTarget is private.
Hook it up to the form or component that will receive the drop.
Enhance GetDataObject, or whatever replacement you have decided, to interpret the external drags that are of interest. This requires more research.
Above generally covers the receiver.
The sender requires yet more research for how to initialise a Drag Drop of the content of interest in Windows.
Repeat for other platforms as required!
Drag and Drop component suite for VCL, https://torry.net/pages.php?id=233, probably has a lot of the code to do this, although I have not looked at it.
If anyone tries this, please update this thread.
Andreas and my answers are about dragging the image itself. In the question you suggest that sending the filename would be acceptable. Following further research to solve my own issue I can give you the categoric answer for this solution, which avoids would be significantly less work.
Drag Drop, as you already know, involves a Source, a Target and Data.
Fire Monkey Drag Drop implementation for internal drags (i.e. within the application) uses its own data format, namely the Data record. For internal drags only the Data.Source property is populated.
For external drags (i.e. between applications, whether FMX or not) OLE has to be used for the data.
All drags can be received by all open applications. But unless OLE data has been set by the Source the Destination will be unable to interpret what the drag is or where it is from. Your question states "I do detect the dragover event in the receiving application but the data property is nil". You are experiencing the situation I am describing.
Delphi FMX will interpret and decode OLE data received for Files and Text content. Files is a list of filenames with paths, not the files themselves. Other OLE content is ignored, such as image. See my previous answer for how to enhance FMX to interpret other OLE content.
Delphi FMX does not set OLE data. Therefore to implement drag drop from a Fire Monkey application to another application, including another Fire Monkey application, it is necessary to write you own start drag code which populates OLE data. In my previous answer this is written more briefly as "The sender requires yet more research for how to initialise a Drag Drop of the content of interest in Windows."
Such Drag Start code would be called from OnMouseDown event of the Source control. For Windows I think
create a COleDataSource
set the data
call its DoDragDrop method
I have not tried it because my application will not be a Source of inter-application drags.

How can I create an Active X control to use Chromium Embedded Framework to replace the WebBrowser control in Powerbuilder 12 classic?

I need to be able to use the modern CSS3 and javascript support of Chrome in a powerbuilder classic 12 project.
I found this post Memory leak with Chromium Embedded interop ActiveX control using CEFSharp WPF
where it seems that a member has successfully created an interop activex control. This is what I need to do and I need some help doing so.
If you want to USE the interop ActiveX control like mentioned in the post you included than simply use it the same way the other person did. Find out where they got the interop control and use it like normal in PB.
I think that you are wanting to develop an ActiveX wrapper which will then be used in PB. As the name implies (wrapper) just create an ActiveX project in Visual Studio and start mapping the properties/events/functions until your wrapper is complete. If you didn't know the basic steps for creating a wrapper than it shouldn't take more than ten minutes on the internet to get an idea of what that is and how to do it.
Also to help you out being a new StackOverflow member, I'd suggest using better tags for the best results. I see why you chose a few of them but 3 of 4 have fewer than 100 followers so your question is not being seen much at all (thank goodness for you on this one). I'd have put this under .NET, C# for top exposure and maybe keep the chromium tag which will help people searching for the answer down the road, it isn't helping you find the answer with less than 100 followers.
Oh, if you need someone to write the wrapper- I am looking for work and can do it for few hours/days pay depending on how much you need exposed.

inspect delphi control object without modify source code

I have an Stock program which developed by Delphi, I want a tools which can read the data from the stock program, for example, the stock price in Delphi grid object.
The Stock program under test is close source, so no chance modify source code which QTP/Robot inspector required. I cannot tell out which Delphi version it is using, neither the object is a standard delphi control.
So anyone can tell out is it possible to inspect that delphi program object data through other technology ?
thanks in advance.
You can use a tool like Winsight to find out the structure of the program window, and use FindWindow and EnumerateChildWindows to find the controls. Then you can use GetWindowText api to get the text of the control. This will work with most controls, but might not work for all. For instance TLabel control has no handle, but does its drawing itself. It has not handle to get the text from and it won't show up in WinSight. You'll have to OCR the window to get those label texts. :p
But this 'testing' sounds more like 'hacking' or 'controlling' to me, if you don't even know what kind of controls are used and which version of Delphi is used, why are you the one testing this program this way?
Trying to read data out of a Delphi grid control is not going to work out for you. It's not like a standard Windows edit control which you could just call GetWindowText on.
If you really want to get the information from this existing program then you'd need to poke at its internal memory or do an OCR on a screen grab. All pretty horrible to contemplate.

i have an OLE automation server (in fact, Open Office Calc) that doesn't close

I have an OLE automation server (in fact, Open Office Calc) that doesn't close. Is there a way I can see what OLE objects are not freed? Truly, I think that because all the variables for this either go out of scope or are set to Unassigned, I shouldn't be having such a problem. as a precaution, I even set the ones (that I found) that go out of scope to Unassigned.
I have been careful to close Open Office Calc in the way prescribed by an example for this.
This might be somehow related to the presence of (embedded) pictures I've been adding to the Office document.
How can I find the cause of this?
I think this is now solved. I found that something about how pictures were being inserted was a "problem". I don't have a complete understanding of why it was a problem but it's enough that it works.
You probably need to display some example source in order to determine the problems you are having. However, you may also want to check out some example Delphi code found online to help accessing Open Office via Delphi: http://www.oooforum.org/forum/viewtopic.phtml?t=8878

How do I do ConnectionPoint in Delphi?

I'm writing a DLL which talks to Excel via its IDispatch interface. From VBA I pass in a Variant containing Application.Caller from which I draw the IDispatch pointer via .pDispVal.
What I'd like to know is how to query the interface via that IDispatch pointer. I want to set up a connection point container, and from there find a connection point to Excel. The ultimate goal is to tie things to Excel's Calculate event and be able to manipulate the Excel data.
I would recommend Binh Ly's timelessly excellent (Delphi) COM tutorials at http://www.techvanguards.com/ which includes chapters entirely dedicated to IConnectionPoint and related mechanisms.
He also offers a free tool for generating EventSink code.
Still, I have a strong feeling that this shouldn't be necessary at all if all you want to do is react to an event triggered by the Excel Application object. Have you tried simply using the wrapper objects that the Delphi Type Library importer generates for you? You can of course also write your own wrappers.
Then again, I haven't actually written any addins for Excel yet - but I do write addins for Outlook and Word for a living and Excel really shouldn't be much different in this regard.
Brian Long explains: http://www.blong.com/Conferences/IConUK2000/DelphiMoreAutomation/More%20Automation%20In%20Delphi.htm#Events
Other resources:
http://dn.codegear.com/article/27126
http://www.gtro.com/delphi/comevents_e.php

Resources