Browse DevX
Sign up for e-mail newsletters from DevX


Using Crossfire 6.0 and Visual Studio to Build Blackberry Applications : Page 2

AppForge's latest version of Crossfire lets you write mobile apps in .NET languages for numerous devices. While this release adds support for Research In Motion's Blackberry, it currently lacks access to PIM and native Blackberry Java functionality.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Building a Sample Project
AppForge provides a number of sample projects that load when you install the product. Two of these have been tweaked to demonstrate specific Blackberry functionality. For example, the animals database project demonstrates how to store records locally on the device. The sample project uses a PDB file to store a small number of records with five fields. You can load and run the sample on the emulator as shown in Figure 1.

Figure 1. Sample Animals Database Project: The figure shows the Blackberry 7100i emulator running the "animals" database sample project.
Here's a snippet of code from the animals sample program to create a new empty database:

dbAnimals_table = afAnimalDB.PDBCreateDatabase( "animals," iType, iCreator) If (dbAnimals_table = 0) Then MessageBox.Show( "Unable to create Animals database.") Return False Application.Exit() End If afAnimalDB.PDBCreateTable(dbAnimals_table, _ "animals," "Animal String,Sound String," & _ "NumberOfLegs Integer,Habitat String," & _ "MethodOfTravel String") Return True

The two parameters in the PDBCreateDatabase call above, iType and iCreator, are integers that hold values needed later to access dynamically created PDB files. You navigate through the database done using well-named method calls such as PDBMoveFirst, PDBMoveToPrevRecord, PDBMoveToLastRecord and such. The Blackberry implementation currently supports only PDB databases.

When you compare the code for adding a new record from the Blackberry version to one for the Palm OS, they look pretty similar.

' Blackberry: Private Sub mnuNewRecord_TrackWheelPress( _ ByVal sender As System.Object, _ ByVal e As AppForge.Controls.BlackBerry.Control.TrackWheelEventArgs) Handles mnuNewRecord.TrackWheelPress CurrentEditMode = modmain.eEditMode.AddRecord MoveToLastRecord() Dim frmEditobj As New frmEdit 'Set up the content before showing the form. frmEditobj.initializeForm() frmEditobj.Show() End Sub ' Palm OS: Private Sub btnNewRecord_ClickEvent( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnNewRecord.ClickEvent CurrentEditMode = modmain.eEditMode.AddRecord MoveToLastRecord() Dim frmEditobj As New frmEdit 'Set up the content before showing the form. frmEditobj.initializeForm() frmEditobj.Show() End Sub

The only real differences are in the name of the subroutine and the arguments. You may need to write more code due to the differences between Blackberry menus and other platforms.

Device Specifics
It's really not practical to try to force some standard set of behaviors on each device for the sake of portability. This is especially true of the Blackberry with its unique thumbwheel device. You have to build distributable code compiled for each target platform anyway, so you might as well add the platform specific stuff to take advantage of any special features.

In general, the idea is to separate all platform specific code into individual projects—all contained in one Visual Studio solution.
AppForge has a recommended best practices white paper (registration required) that describes how to develop applications that need to target different platforms. When you start a new solution you are prompted to select a design target that sets up the default controls available on that platform. In general, the idea is to separate all platform specific code into individual projects—all contained in one Visual Studio solution. You can then use all common code, such as database access routines, across all the platforms.

When you're ready to actually deploy an application to a device, you must make a choice on how you want to deliver it. For simple testing it's easiest to deploy directly to an attached device, but for enterprise-wide deployment you'll probably want to either push the application using the Blackberry Enterprise System or offer it as an "over the air" download.

For testing purposes in this article, I deployed directly to an attached device, because that's likely to be what most developers will use during the development process. You can deploy simple applications by selecting a menu option from within the Visual Studio environment. The first time you deploy to a client device you must also deploy the CrossFire Client, which is analogous to loading the .NET runtime on a desktop computer.

The tricky part comes when you must use signed code. RIM devices are based on the Java OS and have the ability to use signed files whenever you use a specific set of APIs. For example, if your application interacts with the local Personal Information Management (PIM) functions you'll have to sign your application.

You'll need a set of keys from RIM before you can sign an application. RIM charges an "administration fee" of $100 before they will send you the keys. After you have them you can use their signing tool to sign all your applications. While this might sound painful, it does provide a good level of security, particularly in enterprise environments, because signed applications ensure that applications loaded onto corporate devices are authorized.

Currently, CrossFire has limited "real-time" debugging support. If you've developed applications in Visual Studio for Microsoft's Windows CE environment, you're used to having access to the full debugger toolset, including breakpoints, single step execution, variable examination, and so forth. CrossFire's current release does not support any of those features, meaning you have to resort to manually inserting Debug.Print statements or some other "primitive" debugging technique to debug on the device or emulator.

Bottom Line
Although CrossFire 6.0 is a good first step in developing .NET applications for the Blackberry platform, it's only a first step. You can develop some simple apps—but don't expect to do anything that needs access to the low level APIs. For that type of support you'll have to wait for the next version of Crossfire, due out later in the year.

Paul Ferrill, based in Chelsea, Alabama, has been writing about computers and software for almost 20 years. He has programmed in more languages than he cares to count, but now leans toward Visual Basic and C#.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date