Delphi for iOS!

I attended the Rad Studio World Tour today in Auckland. Delphi XE2 has some nice features (x64, OSX, FireMonkey) but the standout for me was the iOS support.Developing for the iPhone et al is mostly a pain in the proverbial. XCode is somewhat of a mess and Objective C was designed by someone with an unholy fetish for square brackets. The last time I did iPhone dev, I did most of my coding in c++ on Windows and only booted into OSX for deployment and testing on the iPhone.Embarcadero are looking to fix that with Delphi XE2. You can write and test your code in Delphi on Windows. When you need to try it on iOS, you create a xcode project (1 mouse click, only needed once) and then boot into OSX and open the xcode project there. From xcode you can edit, compile, run and debug your 100% Delphi code. If you have either Windows or OSX in a virtual machine you can flick from one tother as you wish. Yor app can be compiled and run in both Windows and iOS.Awesome!It's not all perfect, xcode is still there, OSX is a must and the whole code signing is probably as irritating as before, but it's much better than the objective c alternative. It only works with new apps written using FireMonkey but you will be able to pull in older code.The iOS app is full native code, with access to hardware such as gps, accelerometer and camera.Note: Accessing the phone hardware means that your app will no longer run under windows due to either the hardware or the support units not being there. I suspect that this is resolvable with some conditional defines and a bit of hacking.Much to my supprise I am now excited again; both about delphi programming and about iOS programming.
Read More

Delivering software continuously and why you should

I’ve recently really been getting into a Software Delivery methodology which for me, wraps up a selection of the most potent benefits of Agile, TDD, Continuous Integration which requires Development and Operations to work very closely. Holy cow, all those flashy words in a single description, that must mean this is some enterprisey buzzwordy new […] … Read More

Read More

June 17 2011: Software Development Network Event, The Netherlands

On Friday June 17, 2011, the next SDN event will take place in the Achmea Eureko Conference Center in Ziest, The Netherlands will take place, with a full Delphi track consisting of 5 sessions by speakers Brian Long (2), Olivier Olmer, Filip Demuynck, and Bob Swart. Brian Long will talk about Programming for Android with Delphi Prism and Mono for Android, as well as Project Cooper, which brings native Android programming to Delphi developers.
Read More

Developer Issue Report Tool (DIRT) Client screenshots

People who've attended the Delphi XE DataSnap webinar, or read the Delphi XE in Action white paper on "DataSnap XE in the Real World" may have seen the development bits of my Developer Issue Report Tool (DIRT) Server and Client, but here are some screenshots of the most recent build. After you login to the DIRT DataSnap Client (called DirtCleaner by the way), you will get an overview of all issues that belong to you (either because you were the Reporter or the Assigned-To user).
Read More

Delphi XE DataSnap Development courseware and webinar

Within the next 24 hours, I will send out the third edition of the Delphi XE DataSnap Development Courseware manual to all current registered buyers from http://www.eBob42.com/courseware, at 190 pages - now also available as paperback from Lulu.com without updates to the paperback, I'm afraid. The paperback edition of the Delphi XE DataSnap Development courseware manual contains 190 pages, with sections about: DataSnap History and Example Data, DataSnap Server Targets (and Wizards), DataSnap Security, DataSnap Server Components, DataSnap Server Deployment, DataSnap Clients, DataSnap and Databases, DBX: DataSnap Filters, DataSnap REST and Callbacks, DataSnap and .NET Clients, and an appendix about the extended Developer Issue Report Tool (DIRT) Server and Client.
Read More

Working with C++ dll’s from ObjectPascal

It's a well known fact that there are many excelent libraries written in C++, and we, as Object Pascal programmers can take advantage of them. Many times, I have found in forums or mailing lists, questions such as "How can I translate XYZ library to ObjectPascal?", or "How can I use a C++ from Object Pascal?". Well, it's not necessary to translate a library from C++, we can use it just by creating a C wrapper around it.Why I need to wrap the C++ library to C?Because of name mangling, if you look inside the library (using TDump included in Delphi, or by using "nm" on linux), you'll get something like this:000DB314 794 0319 _ZN12DcmAgeStringC1ERKS_000DB274 795 031A _ZN12DcmAgeStringC2ERK6DcmTagm000DB2F0 796 031B _ZN12DcmAgeStringC2ERKS_000DB398 797 031C _ZN12DcmAgeStringD0Ev000DB368 798 031D _ZN12DcmAgeStringD1Ev000DB338 799 031E _ZN12DcmAgeStringD2Ev000DB3C8 800 031F _ZN12DcmAgeStringaSERKS_In the snippet from above, you can see names like _ZN12DcmAgeStringaSERKS. Those names may reffer to functions, methods, constants or variables we can call from Object Pascal by using GetProcAddress. The name in the example, is the "mangled" version of DcmAgeStringa. If the C++ doesn't expose classes, but functions, you can call the functions just by passing the mangled name to GetProcAddress, but what about working with classes?.There's no way to directly use a C++ class from Object Pascal, before using it is mandatory to create a "C" wrapper around it.Let's start by defining a simple C++ class with only one method:#include using namespace std;class Test{ public: Test(); void getHello(char * &AString); };Test::Test(){}void Test::getHello(char * &AString){ const char * str = "Hello World from C++"; strcpy(AString, str);}The class above, can be used with something like this:int main(){ Test * t = new Test(); char * str; t->getHello(str); cout << str;}It just gets change the value of the string "str" and print its contents.As I mentioned earlier, there's no way to create an instance of a C++ class from Object Pascal, but there's a workaround, to create a "C" wrapper around it, and export it from the library.Creating our first "C" wrapper around a C++ classThe idea is to create plain C functions in charge of creating an instance of the Test class, then return a pointer to that instance, then create another function that receive the pointer as param, and use its getHello function.Here's the code:#include #include using namespace std;class Test{ public: Test(); void getHello(char * &AString); };Test::Test(){}void Test::getHello(char * &AString){ const char * str = "Hello World from C++"; strcpy(AString, str);}extern "C"{ void createTestInstance(void * &instance) { instance = new Test(); } void doHello(void * instance, char * &AString) { Test * lInstance = (Test *) instance; lInstance->getHello(AString); } void deleteTestInstance(void * instance) { delete (Test *)instance; instance = NULL; }}If you look at the snippet above, you can see I added code inside an extern "C" block, there will reside the exported functions. I added three functions to create an instance of our class, to use the method getHello, and one to delete the instance.To create a dll from this code, just do this (I'm using Linux here, but you can use MinGW from Windows using the same command):g++ -fPIC -shared test.cpp -o test.soThat command compiles our code and creates a shared object file, in Windows you must replace "-o test.so" with "-o test.dll".Now you can check the contents of the library by using nm or tdump. The result should be something like this:...0000000000000c08 T _fini00000000000008b0 T _init0000000000000990 t call_gmon_start0000000000201068 b completed.74240000000000000ac5 T createTestInstance0000000000000b4e T deleteTestInstance0000000000000b21 T doHello0000000000201070 b dtor_idx.74260000000000000a30 t frame_dummy U strcpy@@GLIBC_2.2.5 U strlen@@GLIBC_2.2.5...You can see, that createTestInstance, deleteTestInstance and doHello now aren't mangled as in the plain C++ library. Now the fun part!The last step of this journey, is to create an Object Pascal program that loads and use the shared library. The program should do this:1) Load the library and store a reference to its handler.2) Execute the method createTestInstance and store a reference to the pointer it returns.3) Execute the method doHello by passing the pointer stored in point 2 as parameter.4) Delete the instance by executing deleteTestInstance and passing the same pointer.Here's the code:program Test;{$mode objfpc}{$H+}uses dynlibs;type TCreateInstance = procedure (var AInstance: Pointer); cdecl; TdoHello = procedure (AInstance: Pointer; var AString: PAnsiChar); cdecl; TDeleteInstance = procedure (AInstance: Pointer); cdecl;var lCreateInstance: TCreateInstance; ldoHello: TdoHello; lDeleteInstance: TDeleteInstance; lHandle: TLibHandle; lInstance: Pointer; lStr: PAnsiChar;begin lHandle := LoadLibrary('./test.so'); if lHandle NILHandle then begin writeln('Library loaded successfully!.'); lInstance := nil; // First, create the instance Pointer(lCreateInstance) := GetProcAddress(lHandle, 'createTestInstance'); if @lCreateInstance nil then lCreateInstance(lInstance); // Second, use the instance Pointer(ldoHello) := GetProcAddress(lHandle, 'doHello'); if @ldoHello nil then begin GetMem(lStr, 255); ldoHello(lInstance, lStr); writeln(lStr); FreeMem(lStr); end; // Third, delete the instance and unload the library Pointer(lDeleteInstance) := GetProcAddress(lHandle, 'deleteTestInstance'); if @lDeleteInstance nil then begin lDeleteInstance(lInstance); UnloadLibrary(lHandle); end; writeln('Done.'); end else writeln('Cannot load library.');end. That's all. Now you can use all your loved C++ libraries from Object Pascal!.
Read More

Why Microsoft and Nokia have a chance

Many iPhone and Android fans don't believe that Nokia and Microsoft have much chance to succeed. While everybody agrees that they wouldn't have a chance without good partners, few seem to agree that they can do much together. The most frequent explanation is that their level of innovation is too low, and their R&D doesn't really work. Most people, however, don't care about the phone producer's
Read More

Learn about Multi-Tier Application Development with DataSnap XE

Embarcadero has just published my new DataSnap white paper where you learn about Multi-Tier Application Development with DataSnap in RAD Studio XE, based on a small but real-world DataSnap application that covers just about everything you can imagine: from secure connections to simple server methods, server methods returning read-only datasets, datasetproviders returning master-detail datasets, with autoincrement primary keys (and how to handle those), using authentication and role based authorisation to secure not only the server methods but also the exposed datasetproviders, deployment and more.
Read More