The Runtime Library provides app tethering components, giving your applications the ability to interact with other applications running either on the same machine or on a remote machine. The RTL provides built-in support for Network (Wifi) and Bluetooth connections.
Using app tethering, you can easily extend your existing applications to mobile. With RAD Studio XE7, we include several demos that showcase this functionality. Today, I thought I would outline how to extend the functionality of your tethered VCL application by adding BaaS (backend-as-a-service) image upload support.
We are going to use the following VCL desktop and FMX mobile demos:
http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE7/Object%20Pascal/RTL/Tethering/PhotoWall/
http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE7/CPP/RTL/Tethering/PhotoWall/
Both demos have the TetheringManager AllowedAdapters property set to Network. You could also tether your VCL desktop app to your mobile app using Bluetooth.
- TBackendFiles (connected to the BaaS provider component)
- TProvider component, such as TKinveyProvider (added AppSecret, AppKey and MasterKey information from BaaS provider account)
- TButton (changed Caption to ‘Upload’)
Setup your button on-click event for uploading the image to the cloud:
procedure TForm8.btnUploadClick(Sender: TObject); var LStream: TStream; LFile: TBackendEntityValue; begin LStream := SaveImage; try BackendFiles1.Files.UploadFile('mypicture55.png', LStream, 'image/png', LFile); ShowMessage('Image has been uploaded'); finally LStream.Free; end; end;
Setup your SaveImage function:
private { Private declarations } function SaveImage: TStream;
function TForm8.SaveImage: TStream; begin Result := TMemoryStream.Create; try Image1.Picture.Graphic.SaveToStream(Result); except Result.Free; raise; end; end;