Category Archives: Objective Pascal

Articles about programming with Objective Pascal in Delphi or Appmethod

Opening a PDF on Android with Delphi

Intents on Android using API 26 to open PDF documents.

Recently, the Google Play store updated its requirements so the target API level of 26 was used to get new apps submitted. While this was reasonably easy to achieve through updating the AndroidManifest.Template, the change to the newer API changed the behaviour of my application.

Before the update, I would download a file to the CachePath and then share to a public folder. I would then get a URI for the public folder path file and share via Intents.  Following the update, this no longer worked. After a little research, I discovered this was due to the changes in the Android security system, that actually, make a lot of sense. Rather than sharing the file outside the application, you now provide tempory access to it via the Intent. To achieve this, you need to setup a Provider, (this is done via XML) and then programmatically provide the path as a ‘content://’ URI, set flags for allowing read / write access via the intent and share it.

The video shows how to achieve this and demo’s the working code. To help, below are some of the XML blocks you will need upon the way.

Adding Provider

Add this to the AndroidManifest.template in the source code root folder, before the </application> tag. This is then used to build all Android apps.

<provider android:name="android.support.v4.content.FileProvider"
android:authorities="%package%.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileprovider" />
</provider>

Provider file

Create a fileprovider.xml (or whatever file name you set in android:resource when declaring the provider).

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="bbresources" path="bbresources/"/>
</paths>

More flags and details for Provider Files can be found on the Android documentation

1000’s attend Delphi Boot Camp’s first session

Delphi Boot Camp add’s YouTube and Facebook streams to service demand.

Today was very exciting in the Embarcadero offices. Developers have been registering for Delphi Boot Camp in their thousands, with over 1000+ registering in the last weekend alone.

Having all this interested in Delphi is awesome, but also has raised quite a challenge for the team delivering Boot Camp due to physical viewing limitations in GoToWebinar. The decision was taken last week that we should add additional ways to stream this out to the 1000’s who were going to attend and Jim McKeeth started off looking into YouTube and Facebook streaming.

StreamingDelphiBootCamp
My Laptop setup with YouTube, Facebook and GoToWebinar

This morning, all attendees received an update email with the multiple streaming options included. During the first of the two live daily sessions we have seen huge numbers viewing on both Facebook and YouTube.

If you couldn’t get into GoToWebinar, either try the second session or watch the replay on YouTube later, keep an eye on community for the replays.

If you did watch the Boot Camp on YouTube, thank you to everyone who joined in with such fun discussions. (my personal favourite question was “So can I talk to Dolphins with this?” – I’ve seen some cool delphi apps, but that would be a nice hardware integration project) Please let us know what you think about these medias for the future.

If you haven't already registered for Delphi boot camp, you can still do so now. Also don't forget to download your 100% Discounted Delphi Starter Edition this week before the offer closes.

You can also use the Starer Edition to qualify for upgrade pricing to RAD Studio or Delphi Pro / Enterprise or Architect editions. And with the mobile add on pack included along with the bonus pack, now is a great time to do that.

 

 

Delphi Boot Camp

Delphi Boot Camp, 100% discount on Starter Edition and Marco’s Book!

Delphi Boot Camp - 5th to 9th September 2016
Delphi Boot Camp – 5th to 9th September 2016

Following on from the recent success of the C++ Builder Boot Camp, attended by programmers from 128 countries, its Delphi Boot Camp time!!

Delphi Boot Camp

Join Embarcadero experts and leading community MVP’s for 5 workshops from Monday 5th September to Friday 9th September.

Focusing on getting stared and using the FMX framework to create cross platform ready code, Delphi Boot Camp is a great way to learn new skills and ask leading experts direct questions on application development.

Date Session Presenters
5th Sept Introduction to Delphi: The IDE and Your First App David I
6th Sept Getting to Know the Delphi Language Marco Cantu
7th Sept Building Effective User Interfaces with FireMonkey Jim McKeeth  & Daniele Tetti
8th Sept Game Development with Delphi Eli M
9th Sept Stepping up to Mobile and Database Development Jim McKeeth
Register Now!

100% Discount on Delphi Starter Edition

To help you with your study at boot camp. Embarcadero are also making Delphi Starter Edition available with 100% discount! All you need to do is register, download and install your Delphi license! But don’t stop there!

Marco Cantu’s Object Pascal hand book!

The final part of the Boot Camp is the programming book! Delphi is the home to modern Object Pascal programming and you can get up to speed with the modern Delphi / Object Pascal language with the help of Marco Cantu’s awesome handbook.

Marco Cantu is the Delphi Product Manager and world leading Delphi expert. His ever popular Object Pascal handbook is available as a free e-download for the duration of the course to anyone on Starter edition! All you need to do is register, download and install the Delphi Starter Edition  and then visit Code Central registered user downloads. To get you there quicker, click  http://cc.embarcadero.com/item/30605.

See you online and happy coding!

Faster FileStream with TBufferedFileStream

Buffering the File Stream in Delphi / C++ Builder

Part of the very fast FireDAC database component library is TFDFileStream,a class that allows high performance access to trace files, (TFDMoniFlatFileClientLink), text data file reading (TFDBatchMoveTextReader / TFDBatchMoveTextWrtiter), SQL Script file reading (TFDScript) and data serialization to file (TFDMemTable etc). Well, it seems it was too good to keep hidden and with the release of 10.1 Berlin, this has been moved from  FireDAC.Stan.Util to System.Classes and has been renamed to TBufferedFileStream.

TBufferedFileStream is a TFileStream descendant that optimises multiple consecutive small writes or reads. In other words, TBufferedFileStream adds buffering support to TFileStream.

As TBufferedFileStream descends from TFileStream it is a simple replacement to add it into your applications and gain the speed benefits it brings.

Read more for code example..

Continue reading Faster FileStream with TBufferedFileStream

Accessing the address book on iOS and Android

Address Book development on iOS and Android

Accessing the Address Book on iOS and Android is a common request for many developers building line of business applications; quickly followed by “and how do I dial a phone number from code“. In this post I will explore how to explore the mobile Address Book using a common code base that works on iOS and Android using TAddressBook. (list to samples and documentation at the bottom of this article)

TAddressBook

With the launch of RAD Studio 10.1 Berlin, Delphi, C++ Builder,  comes a new component, TAddressBook, that enables easy access to the Address Book on iOS and Android.

The TAddressBook lives under Services section of the tool palette and consists of two and has very little in the way of Component properties. It does however have two events that are very useful, and a number of run time methods to call.

TAddressBook Component Events
TAddressBook Component Events

The two events provide notification when the address book has been changed (outside the application) and the result of the application asking for access to the address book.

Continue reading Accessing the address book on iOS and Android

Building Delphi Classes from JSON

JSON to Delphi Classes

I’m currently working on a new blog post showing how to integrate a popular REST API. One of my tasks is to convert JSON to Delphi Objects, so I need to define the Delphi class structures to work with so I can use the TJSON.JSONToObject that I covered previously. I decided to see if anyone had done work to convert JSON into Delphi classes.

Thankfully YES! I found this really handy project JsonToDelphiClass on GitHUB by . The project in covered in the post Introducing JsonToDelphiClass.

The JSON to Delphi Project is a Delphi FMX application that has a simple UI that allows you to modify the automatically created JSON class names which is pretty useful and the code worked first time when copied into my sample. (although I have more playing to do)

The JSON to Delphi tool is definitely a useful resource to work alongside the REST Debugger that you can find in the BIN directory of your RAD Studio install.

Stay tuned for the blog post when it arrives, but in the mean time, if your working with the REST components, I would recommend checking out Petar’s project along side my earlier post on Integrating Microsoft Azure Translation Services into Delphi.

 

Delphi 64bit Code

Updating 32bit code to Delphi 64bit

Ever since Delphi XE2, it has been possible to generate Delphi 64bit applications from the same code base as your traditional Windows 32bit Delphi code. The business case for 64-bit for business is covered in this tech paper The Impact of 64-bit Applications to your Company’s Bottom Line.

On the whole moving to 64bit (on iOS or Windows) is beautifully simple to achieve! It can be just as simple as adding the Delphi 64bit Windows target platform in the project manager and rebuilding the project.

My experience from talking to many developers who have moved up is that normally there are a few things to check in your code but typically its not a massive task to get compiling and ready to test.

A lot has been recorded on moving from Windows 32bit to Windows 64bit Delphi and this should be a useful summary if your just planning now moving up from older versions of Delphi to Delphi 10. If you are building iOS applications, then you will need to use the 64bit build now to get into the AppStore. Thankfully, Delphi has made the task of using 64bit very simple across all platforms and protected us from the headaches non Delphi Developers have had on the whole.

Lets start with this short video from David I who covers some the foundations in 7 minutes!

Continue reading Delphi 64bit Code

LiveBindings in VCL – Part 7 – More LiveBinding Classes

In my earlier posts on Delphi Visual Live Bindings I looked at how to link to bindings via code.

There are a number of classes that help along the way but there are two specific categories of classes and that is what I want to cover in this post.

LiveBindings and List v Link

Sometimes you want to fill a list with values; sometimes you want to keep a list of values updated; this is in essence the difference between using List (e.g. TBindList, TBindGridList) and Link (e.g. TBindListLink, TBindGridLink)

TBindList will fill a list with values, if the data/objects linked to changes then the data will not update unless you manually tell the list to re-populate using the bindings FillLists property.

TBindListLink however will keep the list in sync.

Before you continue… look at the samples

I recommend playing with the “OneOfEach” sample in the samples directory.

{samples}\LiveBindings\oneofeach\vcl

Try changing the fish name in the TBindGridLink and seeing how it updates over the other tabs where the FishFacts data is used.

What is a Binding Source and how is it different to the Control?

Continue reading LiveBindings in VCL – Part 7 – More LiveBinding Classes