Category Archives: C++

See Whats Coming in Delphi and C++ Builder


September 2nd is due to be a very important day in Delphi & C++ Builder history, if the recent news from Microsoft and what I have collated from the “whats coming” posts recently.

Register for the Delphi and C++ Builder “First look”

Spoiler alert!

If you only want to find out whats new when you’re on the “See whats coming in Delphi, RAD Studio and C++ Builder” webinar on the 2nd September, then don’t read further. You may learn

Continue reading See Whats Coming in Delphi and C++ Builder

Database updates in RAD Studio XE8

Database updates in RAD Studio XE8

With RAD Studio XE8 there have been a number of database updates to expand connectivity, and improve and introduce functionality for us programmers.

FireDAC & IBX support for Change Views

FireDAC has introduced new support for Change Views – enabling rapid identification of what has changed on the server side data and updating of client side stored data. See this <2min video for how these work.

Source code for the example ships in the samples directory:

<Samples><language>Database\FireDAC\Samples\DBMS Specific\InterBase\ChangeView

IBX has also introduced new components to make it easier to work with change views and subscriptions.

 New Platform – Teradata

FireDAC now includes support for Teradata, using the driver name TData.

TeraData in FireDAC


An example of how to set the driver properties is shown on the docwiki help for connecting to Teradata with Delphi.


TDataSet TField speed up.

Marco Cantu mentioned on the Launch webinar Q&A a customer was claiming seen a speed up of around 25% on a TClientDataSet application due to the refactoring at the base of how TField is used at the core layer. 🙂 This is really cool for both VCL and also FMX developers.

64bit support for iOS

With the new platform for iOS 64bit, the database layer is also seamlessly available, just recompile and run 🙂

Other updates

There are updates for EMS including push notification. EMS is a great way to access central data from mobile devices. EMS now is updated to include InterBase XE7 for both the server and ToGo side, allowing you to use Change Views on both Server and Clients.

Where FireDAC uses SQLite, it has been updated to a newer driver.

For more of whats new in RAD Studio XE8, including EMS updates, please click here Whats new in Delphi XE8 and C++ Builder XE8


Delphi, C++ and InterBase Community

I’m sure some of you have seen the new Delphi, C++ and InterBase community platform that is being developed at Embarcadero. If not I would highly recommend a visit.

The Embarcadero Community is the new home to blogs, event diaries, latest news and features articles. While the old locations are still working, over time expect to see more and more on the community. Community is also social media ready with links for Facebook, Twitter, linkedIn and Google+

Community Welcome Page

Continue reading Delphi, C++ and InterBase Community

IBLite example from CodeRage 9

The Object Pascal programming source code for the IBLite example from CodeRage 9 that I demo’ed is now available from Embarcadero’s Code Central

The C++ programming version demo’ed requires the data module from the Object Pascal code, so once I’ve cleaned that up I’ll post that as well.

The IBLite example code works on Windows, Mac OS X, iOS and Android.  The session replays are available online via the CodeRage website. – More on the InterBase sessions in my previous post


InterBase CodeRage 28th-30th November

CodeRage 9Register NOW and join me live at #CodeRage!

CodeRage is a fantastic Object Pascal programming and C++ Programming event – highly recommended for any developer, and best of all – REGISTRATION IS FREE!!

Missed it or got a meeting? – Don’t worry, register and you can still get to see the replays!

My two InterBase CodeRage Sessions!

I will be presenting two InterBase CodeRage sessions on Thursday 30th November 2014

  • the InterBase Keynote (8am Pacific / 4pm UK / 5pm CET) where we will be revealing some of the exciting new developments we are working on with InterBase with project DeltaForce!
  • I will also be talking about InterBase’s free edition that can be used on Windows, Mac OS X, Android and iOS – IBLite in the session Embedding local and remote data access into your applications with IBLite (3pm – C++ & 6pm – Object Pascal)

For times and details of all sessions visit the CodeRage website – See you there!!


Mobile Development Lessons – Delphi & C++

Free series of mobile development lessons for Android and iOS based on C++ and Object Pascal.

Earlier in the year the 2nd edition of the mobile development summer school was run by David I and Jim McKeeth. It was great fun doing the first edition and its amazing to see how some of the tech has moved on further in the year since we first ran summer school. This years was more popular than ever and has been made available on YouTube

YouTube Playlist for video replays

Blogs for slides and samples:

To get started is easy!

Download your free trial of RAD Studio

or your FREE edition of Appmethod (C++ Free for Android mobile) 

Happy Coding!

Parallel Programming Thread Pool

In my Parallel Programming introduction post I explored how to easily get performance gains when running loop code by using the TParallel.For() loop construct. A key part of the Parallel Programming Library engine is the new ThreadPool that manages some of the complexity behind the scenes when using this syntax, but more on that later.

Following on from this first post I want to explore a common question I have heard. Is it possible to manage the Parallel Programming library thread pool Size? and if so how?

In short Yes, but I want to pose another question: Should you? – Lets explore this below.

Parallel programming thread pool

The Parallel programming thread pool is very smart! It automatically grows and shrinks based on CPU demand when your application runs and requires its use; it also throttles growth as your CPU usage rises ensuring it doesn’t over cook your CPU and ensuring you don’t lock up your machine. This inbuilt intelligence makes it very efficient and courteous out the box. All of this, without ANY management from us developers! 🙂 So why would you want to change this?

Thats not to say you can’t use a custom(ised) pool. If you do want to limit the size of a pool then you can override the defaults of  a TThreadPool.

TThreadPool Defaults

Defined in System.Threading, TThreadPool initiates with a default of 25 threads per CPU.

MaxThreadsPerCPU = 25;

TThreadPool multiplies the MaxThreadsPerCPU with the number of CPU’s on the machine (it gets this form calling TThread.ProcessorCount) and exposes the result via a read only property TThreadPool.MaxWorkerThreads.

To query the default pool size on your machine at runtime you can use TThreadPool’s handy class method that returns the default pool. With this pool you can then query the MaxWorkerThreads. e.g.

  i : integer;
  i := TThreadPool.Default.MaxWorkerThreads;
  ShowMessage('Pool size = '+i.ToString());

On my Windows VM running 2 cores I see 50, but on my Mac OS X with 8 cores, this code returns 200.

Customising a TThreadPool

Let me start this section by saying, modifying the default TThreadPool properties is not recommended. 

While possible, it is not recommended to modify the Default TThreadPool options as this is a global instance that is used throughout the application, and you never can be sure where and when its being used. You can however create your own instance of a TThreadPool that you modify and use and this is a better approach.

Creating and modifiying a TThreadPool

Creating a TThreadPool is as simple as declaring the variable and calling the constructor.

With an instance of a TThreadPool, you can then modify the MaxWorkerThreads by overriding the value using the method SetMaxWorkerThreads() which takes in an Integer. This sets it at a flat number regardless of the number of CPU’s you have available.  e.g. the following code reports 10 as the Max size on both my Windows and Mac OSX machines mentioned above.

  FPool : TThreadPool;


if Pool = nil then begin
  Pool := TThreadPool.Create;

Note, the MaxWorkerThreads number must always be greater than the MinimumWorkerThreads value that (by default) is set from TThread.ProcessorCount.

A word of caution..

Creating a new TThreadPool come with an overhead. From an initial test where I creating a new TThreadPool for running a small TParallel.For() loop, and then disposing it afterwards it actually decrease performance on your application compared to a traditional for loop. For this reason alone, I would always use a global TThreadPool. When the pool was created globally, the speed performance was immediately backup compared to the create and destroy on demand idea.

 Example of using a custom TThreadPool

Below is an example where Pool is a global TThreadPool.  When the button is selected to run a TThreadPool with a maximum of 10 WorkerThreads. The only adjustments from the example in the previous tutorials is that we now pass in Pool as a paramater to the For loop, note however that this is not being created and free’ed each time in this code.

  Pool: TThreadPool;

procedure TForm5.Button1Click(Sender: TObject);
 Tot: Integer;
 SW: TStopwatch;
 // counts the prime numbers below a given value
 Tot := 0;
 SW := TStopWatch.Create;

 if Pool = nil then begin 
   Pool := TThreadPool.Create;
 TParallel.For(1, Max, procedure (I: Integer)
     if IsPrime (I) then
       TInterlocked.Increment (Tot);
 Memo1.Lines.Add (Format (
 'Parallel (Custom Pool) for loop: %d - %d', [SW.ElapsedMilliseconds, Tot]));

I would say that while this gives me a sense of control, I actually don’t like the fact that I am messing with something that is highly tuned. I would personally conclude that a ThreadPool should be created as the application has initialised and that you use this. Ideally I would say use the default one, as it behaviour is very good already, but if you really want to make more work for yourself, then you can always set the properties of a new pool and use it.

 A thank you to Allen Bauer for his input while writing this post.