If you are building enterprise applications with Delphi XE8 Firemonkey you may run into the situation where you need to remotely control your app on a user’s device without being in front of the device. Firemonkey makes it easy to remotely control an app on Android, IOS, OSX, and Windows. I have created some sample source code which will take a screenshot of the current application and send it to a second application via the app tethering components. The second application will allow you to click on the screenshot and execute the click on the first application. Basically it works very similarly to how Remote Desktop works in windows. Obviously this is a very rudimentary version as it sends the entire screen each time and is not optimized to only send only the parts of the screen that have changed. You could also deploy this same type of system using the TRESTClient instead of the app tethering components as the idea is the same. Basically you could have a support section in your app where the user would click a Start Remote Session or Sync button. Your app would begin sending screenshots to the remote server via app tethering or REST. Each time the app sends a screenshot it could also listen for a click. Once a click is received it could execute the click in the local app which would complete the remote control loop. This same type of functionality can be used to build a Firemonkey test harness. The magic happens in the custom FindControlAtPoint function which was developed for the TImageCacheLayout component. This same idea and code should also work in Appmethod and maybe C++Builder. Here is a code snippet of that function:
function TForm1.FindControlAtPoint(aParent: TControl; aPos: TPointF): TControl;
var
I: Integer;
Control, ChildControl: TControl;
S: String;
begin
Result := nil;
// Check all the child controls and find the one at the coordinates
for I := aParent.Controls.Count - 1 downto 0 do
begin
Control := aParent.Controls[I];
S := Control.ClassName;
if Control.PointInObject(aPos.X, aPos.Y) then
begin
ChildControl := FindControlAtPoint(Control, aPos);
if Assigned(ChildControl) and ChildControl.HitTest then
Exit(ChildControl)
else
if Control.HitTest then
Exit(Control);
end;
end;
end;
Download the sample source code for remotely controlling an app in Delphi XE8 Firemonkey on Android and IOS.