Writing a book application with FireDAC, InterBase IBLite, Visual LiveBindings and more
Being part of a team that travels around talking to developers you can imagine we get quite a range of questions. One of the more obscure in December as "Can you fit the bible into InterBase IBLite?"
The real question was...
Although that is a interesting question, the question really being asked here (due to the context of the session) was "Can we develop an application with InterBase's IBLite database for Android and iOS that contains the text for the bible and get that to Android and iOS from the same code base?"
Although the bible is a big book, its just text and is under 8mb (well within the 100mb IBLite allows for free). So no matter what text you are looking to store, you have loads of space with IBLite.
So to answer the questions in a little more detail, one way to do this is to cover the following challenges.
- Creating a data source that we can show on mobile on multiple platforms.
- Using master detail relationships to make that data accessible and understandable, e.g. have a list of books, chapters and verses.
- Keeping those master detail relationships in sync
- Creating easy navigation in the UI
- Compiling it to Android and iOS
The process in summary...
In short, I managed to find a copy right free edition of the bible translated into English, parse it and import it into InterBase in to a set of tables for Books, Chapters, Verses. Each record has an ID field that linked the Chapter to the Book and the Verses to the Chapters. Relational databases are great for this kind of storage.
Having tested my data was accurate, it was time to build a UI that listed the books and had master detail relationships built into the queries. Using datasets to manage the master-detail relationships, Visual Live Bindings was able to manage the display of the data into a couple of TListViews that I was able to navigate between (so clicking on the book goes to the chapter, and chapter onto the verses) I was also able to add navigation between record using the in built actions for supporting Visual Live Bindings. Finally, I was able to look up the verses for the chapter when the chapter changed to show the text.
How I got there...
In short: using a lot of the skills described in the Delphi Programming - Free Summer School 2013 lessons I built a multi-tab form that moved from page to page with List Views linked via LiveBindings to datasets on my data module.
The key thing with the data was getting the master detail relationship setup. Luckily this is really simple with FireDAC and with Visual Live Bindings.
Params are nothing new, infact they have been a stable of master detail relationships for all time. In short, In your SQL statement, rather than entering the value, you enter a param name prefixed with a full colon ":" - Params are great as they also can be used in any form of SQL statement, and help protect your code from threats like SQL overloading as well. - Not that we expect that to be an issue in this application, but great to know if your writing applications that allow the user to enter values to search on. - anyway - Once the param has been entered, you just need to tell it where to get the value. To do this with master detail, you enter the param name as the field name in the master detail set and connect to the MasterSource to a TDataSource that is linked to the master query. So in the example above, qryBooks has a field called BOOK_ID that the value is automatically collected through the datasource named dsBooks that is read by the query qryChapters.
So thats the data side sorted because when you navigate, the data sets will now update with the correct data for their new master record without having to write any more code!!
Visualising the data
With the data looking after its self, its now just a case of showing it on the screen. This is a simple process and requires zero coding. Using the feature on TFDQuery of storing design time connection only its possible to set the query to Active and view the live data in the IDE at design time. Then using the Visual Live Bindings designer (either right click on the form and choose Bind Visually or go to View > LiveBindings Designer) you can click on the dataset fields and link them to the properties of the list view. In the image above, you can see the ItemHeader.Text being populated with the BOOK_TITLE (green arrow to show that on the screen for illustration) and the Item.Text (which is shown for each record) populating a list of chapter numbers to choose from. The key here thought to ensuring that the list is kept up to date with the current master detail is to draw the line between the Synch property of the list view and the * on the data source. This ensures that all is kept is sync as the data changes.
What is also great with RAD Studio, is that you can see as you build the application, how it looks on other platforms along the way - with live data! All you have to do is choose the platform and device and off you go.
[caption id="attachment_416" align="alignnone" width="167" caption="Choosing Android view on Nexus device"][/caption]
[caption id="attachment_418" align="alignnone" width="261" caption="Swapping between iOS6 and iOS7"][/caption]
The final app!
I intend to create more details around the application at some point just because of the technologies it uses. Would be great if someone wants to take the same structure and add in other books that follow the same structure of Books, Chapters and Verses. You can download the full multi-platforms source code from code central http://cc.embarcadero.com/item/29704
Notes about IBLite & ToGo
IBLite is a run time royalty free mobile database version of InterBase - Embarcadero's multi-platform database for Windows, Mac, Linux, Solaris, iOS and Android that is currently available to developers through RAD Studio developing for Mobile. While IBLite supports all the key features that SQLite supports, plus it also includes additional support for the full SQL92 standard, including Stored Procedures. - InterBase is ideal for the entire product lifecycle as it supports the same in disk structure on all platforms, and with the InterBase ToGo inbuilt Encryption (256bit AES strength), it is the ideal secure data storage to support complete Data Governance initiatives in mobile
Please login first in order for you to submit comments
- Page :