Coderage 9 Snippet - Consuming Object Pascal code from C++ apps using C++11 Lambdas

Written by DavidI on Posted in Tips, Tricks & Techniques

One of my favorite C++ track talks at this year's recent CodeRage 9 conference was Bruneau Babet's excellent "Consuming Object Pascal code from C++" session. There were also many other great C++ talks at this year's CodeRage, but this one was really something special. I've extracted a video from a part of Bruneau's talk where he shows how to use C++11 lambdas where an Delphi developer would use Object Pascal Anonymous Methods. In particular, Lambdas can come in very handy to simplify the use of the new Parallel Programming Library (PPL), which is new in C++Builder XE7. Eariler in the CodeRage 9 schedule, I did a session, "Parallel Programming Library: Create Responsive Apps", showing C++ developers how to use the new PPL. Bruneau took what I demoed to the next level using Lambdas.  I know you will enjoy watching the video snippet and then watching the complete replay for Bruneau's session.


Here is a sample of the C++11 lambda code showing how to use the the Parallel Programming Library's TTask::Run method with nested lambdas:

void __fastcall TForm42::Button1Click(TObject *Sender)
              [this]() -> void {
                const int iter = 5;
                for (int i=0; i<iter; ++i) {
                  TThread::Synchronize(0, MakeAnonMeth<TThreadProcedure>(
                    [this, i]() -> void {
                      String str(DateTimeToStr(Now()));
                      Memo1->Lines->Add(str+((i < (iter-1)) ? " - WORKING AWAY" :
                                                              " - DONE DONE!!!"));


Consuming Object Pascal code using C++11 Lambdas video snippet (16 minutes and 15 seconds) -

if you don't own C++Builder XE7, you can download a free trial and try Bruneau's source code projects using the free trial download link below.

Free C++Builder Trial

Zip file containing Bruneau's slides and demos:


Tags: Appmethod Object Pascal C++ C++11 Delphi C++Builder RAD Studio CPP ISO C++ C++11 Lambda C++ programming Learn How to Consume Object Pascal code in C++ Parallel Programming Library Anonymous Methods Parallel Tasks

Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.

Check out more tips and tricks in this development video: