How to develop n-tier applications for ios using kbmmw starter expert Delphi XE2 With the latest kbmmw beta, it's possible to use just about all of its main functionality on iphones, ipod Touch and ipads. What are the implications for you, the developer? Basically this means that you are able create client and server applications on ios, which can communicate with their surroundings using regular request/response type transports and/or the Wide Information Bus. Your ios application can utilize XML, SOAP, JSON, AJAX, database adapters (there is a SQLite adapter bundled), query and file services, and all the other features bundled with kbmmw. This article describes how to get a kbmmw development environment up and running, and how to create a simple client application that can communicate with a standard Windows-based application server. Installation Prerequisites MacOS with XCodeYou need a Mac with Xcode 3.2.6 or Xcode.0.x (or newer) installed. If you use Xcode 3.2.6, and you want to debug your kbmmw-based applications in Xcode on the Mac, you will need to turn off Load symbols lazily via the Xcode Preferences Debugging menu. On Xcode.0.x you will not need to do that. By Roger Nyberg Delphi/RAD Studio XE2 You need Delphi XE2 or RAD Studio XE2 which both support ios development. Make sure you set up your Delphi development environment according to Embarcadero's instructions which you can find here: http://docwiki.embarcadero.com/radstudio/en/firem onkey_development_setup_for_ios Synapse On ios, kbmmw uses the Synapse transport adapter, hence you will need to download Synapse to your development machine. You can find it here: http://www.ararat.cz/synapse/doku.php. kbmmemtable and kbmmw kbmmemtable (Standard or Professional) and kbmmw (Professional or Enterprise Edition) needs to be installed in your Delphi environment. Make sure you have configured kbmmw for Synapse transport support, by modifying the kbmmwconfig.inc file as follows: {$DEFINE KBMMW_SYNAPSETCPIPTRANSPORT_SUPPORT} {$DEFINE KBMMW_SYNAPSEUDPSAFTRANSPORT_SUPPORT} {$DEFINE KBMMW_SYNAPSETCPIPSAFTRANSPORT_SUPPORT} // Synapse TCPIP support // Synapse UDP WIB support (Enterprise Only) // Synapse TCPIP WIB support (Enterprise Only) On the MacOS, you must ensure that only supported features are defined. It typically (with kbmmw Enterprise Edition) includes: {$DEFINE KBMMW_SYNAPSETCPIPTRANSPORT_SUPPORT} {$DEFINE KBMMW_SYNAPSEUDPSAFTRANSPORT_SUPPORT} {$DEFINE KBMMW_SYNAPSETCPIPSAFTRANSPORT_SUPPORT} {$DEFINE KBMMW_X_SUPPORT} {$DEFINE KBMMW_MT_SUPPORT} {$DEFINE KBMMW_MD_SUPPORT} {$DEFINE KBMMW_SQLITE_SUPPORT} {$DEFINE KBMMW_HTTP_TRANSPORTSTREAM_SUPPORT} {$DEFINE KBMMW_SOAP_TRANSPORTSTREAM_SUPPORT} {$DEFINE KBMMW_XML_TRANSPORTSTREAM_SUPPORT} {$DEFINE KBMMW_AJAX_TRANSPORTSTREAM_SUPPORT} {$DEFINE KBMMW_AMF3_TRANSPORTSTREAM_SUPPORT} // Synapse TCPIP support // Synapse UDP WIB support (Enterprise Only) // Synapse TCPIP WIB support (Enterprise Only) // kbmmw Cross adapter support. // kbmmemtable backend Support. // kbmmw Memory Dataset Support. // SQLite support. // HTTP Tunneling transport stream format. // SOAP transport stream format. // XML transport stream format. // AJAX transport stream format. // AMF3 transport stream format. 55
How to develop n-tier applications for ios using kbmmw (Continuation 1) You can use {$IFDEF IOS} {$ELSE} {$ENDIF} to include and exclude sections in the kbmmwconfig.inc. That will allow you to use the same kbmmwconfig.inc file in both Mac and Windows environments. All source code for kbmmw and Synapse needs to be made available both on your Mac and on the PC where Delphi is installed. You can accomplish this by making a shared folder on a network drive, to which you copy all kbmmw/kbmmemtable/kbmsql/synapse source files (*.dfm, *.lfm, *.pas, *.inc). Configuring the Free Pascal Compiler on MacOS Set up your path to the source code by modifying /etc/fpc.cfg. It contains a section with lines ning -Fu/. In that section you need to add additional lines with absolute paths (seen from the Mac's perspective) to all the directories containing the above mentioned source files (e. g. Fu/Users/someuser/somepath/kbmmw). /etc/fpc.cfg is a protected file, so it can only be overwritten by the system administrator. That requires using the sudo command. An example scenario would be to start a terminal server on MacOS and do the following: cp /etc/fpc.cfg. vi./fpc.cfg Alter this according to your setup (Instead of vi you could also use MacOS TextEdit) sudo cp./fpc.cfg /etc/fpc.cfg Making your IOS client application After these required files have been edited and copied to the correct folders you are ready to create a new IOS HD application in Delphi. Click File New Other and select FireMonkey HD ios application. When you finish creating the application framework (via the wizard), you will see a FireMonkey form shown. Save the application project and units to a directory that is shared between your MacOS and Windows environments. Let's say we name the project client. You may notice that the kbmmw components are disabled (grayed out) or do not show up in the component palette. To fix that, close the Delphi project, and via the file explorer, find the project directory and delete client.dproj (only that one file!). Then reopen client.dpr in the Delphi XE2 IDE. Now both kbmmw and kbmmemtable components are available. This also allows you to code, execute and test your application on Windows. When you come to put business code into your application this will make development much easier. Notice that most but not all FireMonkey features are working on ios. When you are satisfied with your application, you can export it via the Xcode exporter and test to check that it can compile and run in the ios environment. When you are satisfied, choose the menu Tools Export to Xcode in the Delphi IDE. Figure 1: Start Finder on the Mac, and locate the client.xcodeproj file. Double click it on the Mac, which will open the Xcode environment. 56
How to develop n-tier applications for ios using kbmmw (Continuation 2) Figure 2: Xcode opens up: Figure 3: Click Build and debug If the compilation on Windows or MacOS fails, stating it can't find specific standard units, then add the word FMX to the unit scope names. In Delphi: Project Options Delphi Compiler Unit Scope Names 57
How to develop n-tier applications for ios using kbmmw (Continuation 3) Figure : When the compilation succeeds, it will automatically start the ios emulator, and run the application in it. Figure 5: Let's click the Run Query component. It will ask a kbmmw-based application server for data from the standard demo database 'Events'. What does this sample client contain? The client application demonstrated in this article contains some TEdits, a TMemo, a TImage, a couple of TButtons, and some kbmmw client components (TkbmMWTCPIPSynapseClientTransport, TkbmMWClientConnectionPool, TkbmMWClientQuery, TkbmMWBinaryStreamFormat). 58
How to develop n-tier applications for ios using kbmmw (Continuation ) procedure TForm1.Update; var ms:tmemorystream; bs:tstream; if kbmmwclientquery1event_name.isnull then Edit1.Text:='(n/a)' else Edit1.Text:= kbmmwclientquery1event_name.asstring; if kbmmwclientquery1event_description.isnull then Memo1.Text:='(n/a)' else Memo1.Text:= kbmmwclientquery1event_description.asstring; if kbmmwclientquery1event_photo.isnull then Image1.Bitmap.Clear(TAlphaColorRec.Red) else bs:=kbmmwclientquery1.createblobstream (kbmmwclientquery1event_photo,bmread); try // Required to skip 8 bytes of header. Embarcadero 'detail'. bs.position:= 8; Image1.Bitmap.LoadFromStream(bs); finally bs.free; The [Next] and [Previous] button handlers are as follows: procedure TForm1.btnNextClick(Sender: TObject); kbmmwclientquery1.next; Update; Figure 6: Form1 in sight procedure TForm1.btnPrevClick(Sender: TObject); kbmmwclientquery1.prior; Update; As there is no true data binding available on ios at the moment, we need to populate the TEdits, TMemo and TImage in code. Application server on ios? The event handler for the [Run Query] button contains this code: If you want to create a kbmmw-based application server that runs on ios, you do it in the same way as if you were creating a kbmmwclientquery1.close; regular ios application, merely adding kbmmw application server kbmmwclientconnectionpool1.killconnections; components as described in other articles. kbmmwtcpipsynapseclienttransport1.host:= Because ios supports SQLite as its only database type, only eip.text; the kbmmwsqlite database adapter can be used on ios (in kbmmwclientquery1.open; addition to the kbmmwmd and kbmmwx adapters). kbmmw's Update; SQLite database adapter is intelligent enough to map most data types for easy integration. It ensures that the query dataset is closed (if it was opened on a previous If you are adding a SQLite database file to your IOS device click), and in this example we force disconnections of all TCP/IP you need to make sure it's read/write. Adding it to the application connections between the client and server applications. path/package will cause it to end up read only. This is purely optional. In fact one would probably want to use If you are running a server on ios, Unicode is not the kbmmw failover/loadbalancing/reconnect features to ensure supported for regular strings, and Unicode clients must be that a connection is established to a capable application server from configured to communicate in a non-unicode way with the ios a farm of application servers, if you plan to serve millions of ios server. You do that by setting the client's transport parameter devices. correctly: e. g. Update is a method that ensures that the current record in the query component is displayed in the visual controls. The reason is kbmmwtcpipindyclienttransport1.params.values that data binding is not fully supported in FMX on ios. [KBMMW_STREAM_FORMATTER_PARAM_NOUNICODESTRINGS] := '1' Hence our update method looks like this: Notice that wide strings are supported on ios and datasets containing ftwidestring fields are fully supported. However, service names and versions must be ansi strings; hence the above setting. Happy n-tiering on ios! 59
New V.10.00 available for DELPHI XE2-32 and 6 On ipad and iphone Full kbmmw support The Delphi Starter Edition now also has the ability to do multi tier development for no cost at all. Pro/Ent is available for Win32/Win6/OSX/FPC The CodeGear Edition is for Delphi XE2/Win32 only and provides access to SQLite in addition to the standard Delphi Starter Edition database connectivity frameworks, BDE and IBExpress. Delphi Starter Edition also lacks proper XML support and the local TClientDataset, which is also to be found as part of kbmmw CodeGear Edition in the form of TkbmMWDOMXML and the high performance TkbmMemTable. In addition its possible to upgrade to kbmmemtable Standard Edition for only US$30. The upgrade includes full source for kbmmemtable, and includes kbmsql which provides a SQL frontend to kbmmemtable. (client and server) For kbmmemtable now available: full XE2 support (32/6/osx) For kbmmw there are multiple new items: Remote Desktop Client/Server/Proxy Support, NEW JSON support, JSON streaming of kbmmemtable datasets, bugfixes and more. Improved HTML template support, improved Cookie Support etc. Lots of improvements related to using kbmmw as a web server producing dynamic web pages. kbmmemtable on Win6. Tests done: 10 million records in memory with multiple fields and indexes... ESB, SOA,MoM, EAI TOOLS FOR INTELLIGENT SOLUTIONS. kbmmw IS THE PREMIERE N-TIER PRODUCT FOR DELPHI / C++BUILDER BDS DEVELOPMENT FRAMEWORK FOR WIN 32 / 6,.NET AND LINUX WITH CLIENTS RESIDING ON WIN32 / 6,.NET, LINUX, UNIX MAINFRAMES, MINIS, EMBEDDED DEVICES, SMART PHONES AND TABLETS.