hcOPF an ORM for Delphi

What is an OPF?

An object persistence framework is essentially a library of pre-written code that takes care of the details of persisting, or permanently storing an object. The object may be persisted to a text file, XML file etc., but in the business world it will most likely be to an RDBMS and for this reason they are sometimes referred to as an ORM (Object Relational Mapper).  Object databases have been around for some time, but they are not used as prominently as RDBMS products so programmers still have to be able to write their objects into a RDBMS, and the easiest way to do that is create an Object Persistence Framework, or layer, that can perform all the CRUD (Create, Read, Update and Delete) operations developers normally have to code by hand.  This enables developers to focus on implementing better UIs, and addressing the problems the application is meant to solve.

The concept of an OPF is nothing new.  Java has TopLink, Hibernate, etc, .NET has a partial port of Hibernate called oddly enough, NHibernate, CSLA, Castle Record and numerous other implementations.  One of the major impediments to an OPF for Delphi is the lack of complete RTTI aka Reflection, and the development environment itself.  Delphi’s IDE is geared to creating RAD applications using it’s component technology.  While this means you can create Object Oriented applications quickly, the benefits of OOP are for the most part lost, because the data is not being manipulated in an object oriented fashion.  As a result code becomes harder to maintain and understand because data validation code is scattered throughout form and data modules.  The use of events on TDataSets can create a spider web of event sequences that produce obscure bugs that are difficult to trace, and more database activity is usually required in a typical RAD application than a truly object oriented one.

How it All Began

My interest in OPFs began when working for a company that developed their own OPF as the foundation for a suite of hospital medical applications written in Delphi 3.  That company went bankrupt, but the validity of their vision of using an OPF as a foundation for applications was proven to me every time I wrote a database application afterwards.  The more complicated the application, or the more closely it modeled the real world, the more sense it made to use an OPF and write a fully object oriented application.  Eventually, I started working on my own OPF, ensuring that I didn’t make the same design mistakes that were made in the other framework which was later sold as ObjectSight.  I wrote a basic requirements document, and proceeded to develop the OPF, reworking it over time as I came across other ideas from Seleqt, Techinsite, Phillip Brown, Thomas Buxton, Frank Shearer, Chris Lichti, and participants of the Obiwan project and Object Oriented Design discussion groups.

I am happy to say that I licensed an earlier version of this framework to a client, and have used it on numerous projects myself, including one for the company at which I currently work.  I love the fact that I don’t have to write SQL and the more I use the framework, the better it gets.  The latest improvements include support for practically any non-data aware control via the MGM pattern.  It also supports the DeveloperExpress suite of controls including their very powerful grid by way of a custom datasource.  For reporting, I have implemented support for an engine I have used for a long time, and found to be very reliable.  Unlike RAVE they have stood the test of time, and still have great support; ReportBuilder.  hcOPF supports reporting directly from objects in memory by way of ReportBuilder’s JITPipeline objects; flexibility which is a testament to their design architecture.

I have dubbed the framework hcOPF where hc stands for Hengen Computing.  The framework is much more than just an ORM.  It provides an architecture for data input validation, object binding, and reporting as well as persistence.  All this, and it works with Delphi 7 to XE2 even providing cross platform support with FireMonkey.  With the design-time support built in to the framework, and my hcOPFCodeGen tool, it can be as fast to develop using hcOPF as using the traditional Delphi RAD approach, and it will save significant time in maintenance of the project during it’s lifetime.