Quantcast
Channel: Sarina DuPont, Product Manager RAD Studio
Viewing all articles
Browse latest Browse all 132

Tether your VCL Apps to Mobile and the Cloud

$
0
0

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.

The only code added to the demo we ship with RAD Studio XE7 is code for uploading the image to the cloud. You will need to put the following components onto your VCL form:
  • 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’)
To change the style of your VCL application, go to Project->Options->Appearance. In this case, we selected our Metropolis UI Dark style.


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;
Mobile App running on an iPod Touch
VCL App running on Windows 7
Uploaded image shown in BaaS account


Viewing all articles
Browse latest Browse all 132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>