Friday, February 24, 2012

Developing for mobiles - short summary

Here are some links about the present mobile operating systems:

A. iOS - Apple - http://developer.apple.com - full sdk is available only for apple developers - (to become a developer one must pay 99$ per year, and then have full access to resources), and you'll need a Mac osx hardware, in order to compile the iOS code on.. Development by default is done with Objective-c (variation of c), yet there are other possible programing for iOS such as in Delphi XE2 (objective pascal). Delphi XE2 uses FPC in order to build the iOS based apps (using a technology called FireMonkey - FMX). The iOS is evolution of the standard MacOS -- and got many of its known MacOS interface to build apps with. Programming Applications for the iOS is being reviewed by Apple development tool, and being published on a www site, called AppStore it can be accessed as well from the Apple iTunes application., currently there is a huge amount of free and commercial applications on the AppStore, for a couple of years the AppStore was a very successful and well known site.

B. Android - Google - http://developer.android.com/sdk/index.html - there are about 4~5 versions (each version is nicknamed for example, ICS - ice cream sandwich - version 4), development is being done using java. According to present date Delphi XE2 doesn't support compilation for android. Yet there are possible ways to compile FPC with a wrapper for that OS. In the coming month Embarcadero will add this compilation support for that OS on Delphi XE2. Android was produced by Google a couple of years ago, and got a very tight and big customer base. It is based on the Linux architecture, and got a well published API for use. Programing Applications for the Android can be sold from a www site, called MarketStore - currently there is a huge amount of free and commercial applications on the MarketStore.

C. WebOs - Palm - HP - https://developer.palm.com/ - HP, Palm mobile os - requires a Virtual Box, which is an oracle visualization tool. This mobile os, had its switch of hands a couple of times, yet still has some tablet, and mobile based OSes on the market.

D. Windows 8 - Microsoft - http://www.buildwindows.com/ - next generation of Microsoft windows - for pc & tablets (both intel and arm based CPU) - beta for developers include the latest visual studio 11 - to build win8 based metro apps. Delphi will add support for Metro based apps for win8 later this year. On 29th of feb 2012, microsoft will release a second more enhanced beta containing many sample apps (such as email reader, picture presentation, etc). Microsfot has announced that it will have its www site, for selling and buying Win8 Metro based applications. It wasn't yet revealed for the wide public. According to current news Nokia has signed a contract with Micrsoft to distribute the windows 8 OS in its next generation of tablets and mobile devices.

E. Blackberry os - https://bdsc.webapps.blackberry.com/air/ - as far as I could gather the programming for this type of Operating System, is being done with Adobe AIR tools.

This is the list of known OSes for mobile that I know that are still valid widely in the current market - As an enthusiast of operating systems, since the desktop OSes, and a  collector of the different variations - If you have any other OSes that you would like to introduce for the world post a comment on that post. I'd love to learn more about possibilities of mobile OSes.

Wikipedia got a nice features table  of the current OSes http://en.wikipedia.org/wiki/Mobile_operating_system#Mobile_OS_comparison - You can find many more resources of each one of the Mobile OS on different www sites.

Monday, December 5, 2011

FMX iOS/MacOSX SDK encapsulation

One of the best coded libraries, as far as I know, is the OOP VCL. It contains all the possible variations of encapsulating  the Win 32/64 OS SDK. In almost any possible way you look there is an OnEventNotify, or a built class in order to enable the programmer - to enhance his code, or interfere and put his code according to what he would like to program.

However when looking at the FireMonkey, on this stage at least, it lacks these procedures and events. The main focus of the FMX is on the 2d/3d Library abilities. However when one would like to use the FMX as an OS encapsulated tool -- such as within the VCL example -- it will fail.

Nonetheless I am quite sure that Embarcadero programmer and community is on its way to programming the OS related  (MacOSX, Apple mobile iOS -- and furthermore -- the Google Android, or the blackberry) classes encapsulation.

Notification in iOS using Delphi XE2 FMX
An example where I encountered this lack of OS (in my case iOS) SDK encapsulation -- is on the following example:

I've been programming a small application for iOS using the Embarcadero Delphi XE2 FMX. One portion of the code was dedicated to sending an iOS notification messages -- which is a service that Apple interduced for programmers in order to send Messages much like the SMS architecture -- only the notifications are the wifi messages. Registrating the  Push notifications on iOS, and registrating the deviceID in the remote server was a part of the code that needed to be done.

The following code is a xcode iOS objective-c code, demonstration  of the code to put -- on the sample the code is apart of the ApplicationDelegate.m file on the iOS, the ApplicationDelegateProtocol is well documented under the developer.apple.com pages:

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | 
UIRemoteNotificationTypeAlert)];

    return YES;
}

- (void)application:(UIApplication*)application 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
} 
 
As you can see the code uses two objective-c events, that make the device notification part possible.
However I had to translate that from objective-c to FPC objective-pascal.The important thing is where is code will be put in. On the FMX platform the Application Delegation is being done as an object that register the main Form of the XE2 FMX application. 
The following code was taken from the FMX_Platform_iOS.pas file from the source of the FMX code:

type
  ApplicationDelegate = objcclass(NSObject)
   procedure applicationDidFinishLaunching(notification: UIApplication); 
message 'applicationDidFinishLaunching:';
   procedure applicationWillTerminate(notification : UIApplication); message 
'applicationWillTerminate:';
  end;
 
Extending the ApplicationDelegate objclass can be done by a 'helper' class of the objective-pascal called a category -- which according to the documentation will virtually extend the objclass. However, there is an obstacle the ApplicationDelegate objclass is being implemented in the unit, but isn't being introduced to other units, meaning it isn't being registered in the interface part of the unit.

Friday, November 25, 2011

Saving/Loading TStream on iOS device using FPC

I've programmed a small application for iOS using the XE2 and FMX capabilities.
Anyhow, when reaching the stage where I needed to save the data, I've encountered a problem of a foreign language with the FPC.



While using the XE2 strictly with the win32/64 environments there is no such problem of encoding cause of the unicode abilities of the development tool.

However, while porting that to the iOS there need to be a consideration of the FPC limits so far. I've been using the TWideStrings object which does the unicode properly. 

There is a sample code writing text to the iOS device on embarcaderos site -- but that didn't help me much due to the use of the foreign language that the application was attended to. When saving the data to the iOS device, I needed to write additional code that writes the data without any consideration of its language - in a binary style if one can.

The following code is to save/load TStream on an iOS device using the FPC, that I have written:

Sunday, September 25, 2011

Delphi XE2 learning curve

Prefix
If you are an Embarcadero (ex codegear [ex Borland]) Delphi programmer -- and started programming with the latest Delphi xe2 release, you must have asked yourself a couple of questions regarding it.

Delphi xe2 has introduced a bunch of new technology programming abilities -- which make the learning curve a little bit slower -- yet on the long run will produce excellent products.

First of all -- cross platform --
Delphi now can produce applications for a couple of platforms:
Microsofts Windows - win 32bit, win 64bit
Apple - OSX (desktop devices) and iOS (portable devices iPad, iPod, iPhone)
In the for coming future also:
Google - mobile android os
Microsoft - windows 8 metro style os

To make these cross compilation, Delphi's developers added to the compilation environment - FPC (free pascal) which is deployed on the Mac OSX. In order to develop on a Mac one should be register to Apple, and have a Mac computer. After preforming that you should download the Xcode and OSX, iOS sdk. The compilation of your Mac application will be done from Xcode which would use the FPC and the FMX (firemonkey platform) libraries. Both the FPC and FMX are supplied in the installation of the delphi XE2 - copied to the Mac computer and installed on it.

The FMX is a set of development objects code that enable you to compiled on the Mac after preforming the short guide lines I gave on the previous paragraph.

2d & 3d graphics
The FMX enables you to create impressive 2d and 3d applications. The use of the CPU and GPU are taken into effect when running the code you write.

Although I am not a stranger to the 3d models design. I never designed anything nor used a designer tool for that matter... Yet, when starting with the FMX one of its great abilities the the tight code written to 3d design. FMX contains components of 3d design that would be familiar to designers such as standard 3d objects, camera object, light and so on.

Delphi programmers could find on the web a set of tools such as DXScene that contains the same abilities of the FMX -- however, when purchasing the delphi xe2, you get all these abilities "built in" the environment.

Some slow downs
Unfortunately developing on this stage on Delphi XE2, would be a tricky thing. Due to lack of information on the help files. I find it useful drilling down the code of delphi in order to see what an object could do, or what is its properties and API.

If you are developing for the Mac OSX/iOS you'd find it usefull to know the Free Pascal. For example Embarcadero developers didn't map all the api that can be supplied from the various iOS devices -- and using for example GPS or sound and much more, can be done though one should know that it'll require a bit of objective-pascal code (which are the objective-c api to the iOS devices written for object pascal).

The FireMonkey was originated from a third party tool called VGScene -- which initially had the abilities of the linkage between the Delphi and the FPC. I was registered to the VGScene thus I had to use for my project an interface that was totally mapped back then on the VGScene, same goes on the FireMonkey platform.

Mid-conclusion
If you are planning a project that should be ported to Mac OSX, iOS and win32, win64.. the RAD studio is for you. If you would like to use high 3d manipulations or 2d graphics manipulation on your app -- I would give you the same conclusion.
It would be a good time to get into the programming of apps using the RAD Studio. For number of reasons:
1. DB support. Although modified from the other versions of the Rad.
2. FireMonkey support for cross platform compilation on Mac and Windows.
3. FireMonkey 3d and 2d programming.
4. Modified programming features such as LiveBinding of components.
5. Vast historical expertize on the programming environment tools in the market. Starting back from the Turbo Pascal -- which was for DOS environment -- downto the Current Delphi XE2 release