RTL.DesktopCast Sample
DesktopCast is a sample application with a client-server architecture where a client application can connect to a server application and receive a screenshot taken by the server application once or every 5 seconds using app tethering. The server application is a VCL application, and the client application is available both as a VCL application and as a FireMonkey application.
Contents
Location
You can find the DesktopCast project at:
- Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to either of the following folders:
- CPP\RTL\Tethering\DesktopCast
- Object Pascal\RTL\Tethering\DesktopCast
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
This group of projects provides two client projects (VCL and FireMonkey) and a server project. The projects are designed so that at a given time you have one of the client projects and the server project running and reachable using app tethering.
In the server application you have the following buttons:
- TakeFullScreenShot takes a screenshot and shows the screenshot.
- StartLiveCast starts taking screenshots each 5 seconds and showing them.
- StopLiveCast stops taking screenshots.
In the client application you have the following buttons:
- Connect establishes a connection to the running server application.
- When the connection finishes, you can see text at the top of the application, over the control buttons. If the connection failed, the message says "You are not connected". If the connection is successful, the message says "Working with: - TTetheringAppProfile1".
- TakeFullScreenShot or TakeShot executes the server action to take a screenshot remotely.
- StartLiveCast or Start Cast executes the server action to start taking screenshots every 5 seconds remotely.
- StopLiveCast or StopCast executes the server action to stop taking screenshots every 5 seconds remotely.
When the server application takes a screenshot, the server application shows the screenshot and shares the screenshot with the client application, that also shows the server screenshot.
The window title of the VCL client application shows also information about the received screenshot (size and date).
How to Use the Sample
- Navigate to the location given above and open DesktopCast.groupproj.
- Double click the server application entry, VCLTetherDesktop, in the Projects Window to select the server application.
- Select Run > Run to run the server application.
- Double click one of the client application entries, FMXClientTetherDesktop or VCLTetherClient, in the Project Manager to select a client application.
- Select Run > Run to run the selected client application.
Files
Each application in the project group contains a single source file that contains the class for the main form of the application.
Classes
Each application defines a single class that implements the main form of the application.
Implementation
Server Application
- ActionManager1 defines the following actions (associated with the application buttons):
actFullShot
executesactFullShotExecute
, which updates the screenshot inImage1
usingShot
and saves the screenshot to the value of the shared local resource.actStartCast
executesactStartCastExecute
, which enablestmCast
.actStopCast
executesactStopCastExecute
, which disablestmCast
.
- DesktopTetherManager.Password is "Desktop".
- TTetheringAppProfile1:
- Actions contains three local actions that are associated with the actions in
ActionManager1
and are shared with remote profiles. - The Group is "TetherDesktop".
- The Manager is
DesktopTetherManager
. - Resources contains a single local resource which is shared with remote profiles. The Kind property is TTetheringRemoteKind.Shared.
- Actions contains three local actions that are associated with the actions in
- There are two methods to take screenshots:
- The class contains the following members for timing:
- tmCast is disabled by default. When enabled, this timer runs the
tmCastTimer
procedure each 5 seconds. - tmCastTimer executes the
actFullShot
action.
- tmCast is disabled by default. When enabled, this timer runs the
FireMonkey Client Application
CheckRemoteProfiles
updates Label1 with information about the connected remote profiles, if any.- CommandManager.OnRequestManagerPassword is handled by
CommandManagerRequestManagerPassword
, which provides the password of the remote server application: "Desktop". - CommandApp:
- Actions contains three local actions with
Mirror
as Kind and the same names as the actions shared by the server application. These actions are associated with the actions inActionList1
. - The Group is "TetherDesktop".
- The Manager is
CommandManager
. - Resources contains a single resource with
Mirror
as Kind and the same name as the resource shared by the server application.
- Actions contains three local actions with
- ActionList1 defines the same actions as the server application, with the same name, but no implementation as the actions just trigger their remote twins. These actions are associated with their corresponding buttons.
- tmCheckConnection is disabled by default. When enabled, this timer runs the
CheckRemoteProfiles
procedure each 2 seconds. - Button2 (Connect) when clicked:
- Calls CommandManager.AutoConnect.
- Enables
tmCheckConnection
.
VCL Client Application
CheckRemoteProfiles
updates Label1 with information about the connected remote profiles, if any.- DesktopTetherManager:
- OnEndAutoConnect is handled by
DesktopTetherManagerEndAutoConnect
, which callsCheckRemoteProfiles
. - OnRequestManagerPassword is handled by
DesktopTetherManagerRequestManagerPassword
, which provides the password of the remote server application: "Desktop".
- OnEndAutoConnect is handled by
- TTetheringAppProfile1:
- Actions contains three local actions with
Mirror
as Kind and the same names as the actions shared by the server application. These actions are associated with the actions inActionManager1
. - The Group is "TetherDesktop".
- The Manager is
DesktopTetherManager
. - Resources contains a single resource with
Mirror
as Kind and the same name as the resource shared by the server application.
- Actions contains three local actions with
- ActionManager1 defines the same actions as the server application, with the same name, but no implementation as the actions just trigger their remote twins. These actions are associates with their respective buttons.
- tmCheckConnection is disabled by default. When enabled, this timer runs the
CheckRemoteProfiles
procedure each 2 seconds. - Button4 (Connect) when clicked:
- Calls DesktopTetherManager.AutoConnect.
- Enables
tmCheckConnection
.
Uses
- System.Tether.AppProfile.TTetheringAppProfile
- System.Tether.AppProfile.TTetheringAppProfile.Actions
- System.Tether.AppProfile.TTetheringAppProfile.Group
- System.Tether.AppProfile.TTetheringAppProfile.Manager
- System.Tether.AppProfile.TTetheringAppProfile.Resources
- System.Tether.AppProfile.TLocalResource
- System.Tether.AppProfile.TLocalResource.Kind
- System.Tether.AppProfile.TLocalResource.Value
- System.Tether.Manager.TTetheringManager
- System.Tether.Manager.TTetheringManager.AutoConnect
- System.Tether.Manager.TTetheringManager.OnRequestManagerPassword
- System.Tether.Manager.TTetheringManager.Password
See Also
- System.Tether unit
- BDShoppingList sample
- MediaPlayer sample
- PhotoWall sample