Delphi Advanced Tools: UML, Unit Testing, Audits, Metrics, and Refactoring

By: Tim DelChiaro

Abstract: Article reprint from Blaise Pascal Magazine

Article by Mike Rozlog in the April 2010 issue of Blaise Pascal Magazine

    Part I:

Being the Product Manager for RAD Studio (Delphi, C++Builder, and Delphi Prism) is always interesting, and not a day goes by that I don’t hear somebody make the statement that Delphi or C++Builder are OLD. When I have the opportunity to talk to the person making the statement, usually by the end of the conversation the person I’m talking to has a much different opinion of Delphi and C++Builder.

One of our current challenges with regards to developing applications with Delphi and C++Builder is that the entire community must stand up and let anybody who will listen know, that Delphi and C++Builder are cutting edge languages, tools, and environments that can build any application on the Windows platform.

    Delphi developers are not cutting edge developers… really?

Along with the fact that many developers think that Delphi and C++Builder are old, there is also the perception that the developers are old and out of touch. Again, we as a community need to dispel this rumor and let people know that we understand cutting edge concepts, tools, and approaches.

The areas that seem to resonate with managers and the outside developers revolve around language and tools. Now, anybody who has used Delphi or C++Builder in the past 10 years knows that the IDE itself is up-to-date and in many cases leads with new functionality like the new IDE Insight that allows you to find any feature or function within the IDE with a few keystrokes. As for the language, we are not going to focus on that particular issue in this write-up, but it may be written about in the future. This is focused on the advanced tools found inside the IDE that help developers build better software, faster, period.

    Why would I use these tools in Delphi?

This usually spawns two (2) questions, what are these tools you speak of and why would I use them? The exact tools focused on in this write-up include UML Visualization, UML integration, Unit Testing, static code analysis with both Audits and Metrics, and finally Refactoring.

This leads to the second question; why would a Developer use these tools? It can be broken down into a few categories. This first being better communication. It has been said that a picture is worth a 1000 words, it can also be said that a picture can explain a 1000 lines of code. So, using a feature like UML Visualization allows more developers to communicate better with the code. Then using the Enterprise edition, they can use the full UML integration to describe and help build the code. The next reason is to increase quality and reduce complexity.

This can be accomplished by using the integrated Unit Testing that is based on the widely used Java Testing Framework called (JUnit), which Delphi and C++Builder is based on DUnit. This allows developers to build unit tests quickly and easily into the product and ensure code is working as designed. Couple this feature together with static analyses like Audits and Metrics and things become very interesting.

Finally, once you can figure out where issues exist in your code, it may be time to refactor, this is not a update or maintenance process, Refactoring is taking existing code and rewriting it to be easier to understand, easier to maintain, and/or a better implementation. NOTE: Refactoring does not change the behavior of the code, meaning if I have two numbers being added together, ie: 2 + 2 = 4 and the developer decides to refactor the method that adds the numbers together, when the developer is done the method will still add 2 + 2 = 4. So when you couple Unit Testing together with Refactoring, it becomes a very powerful approach to maintaining code and increasing functionality.

    What is UML Visualization?

Before I answer the above section question, it may be helpful to just review what is UML? UML is Unified Modeling Language and is a generic way to represent code with graphic models. These graphic models show objects, relationships, and requirements in a graphical form. This allows some developers and business people to communicate easier than to look at a lot of code:

Hide image
Hide image
Click to see full-sized image

The above example, one is a model and one is the code, and for many business and developer people looking at a picture is easier than looking at raw code, thus the model is easier to comprehend what is going on. Now, as you can see that is a very easy example, but what about something that everybody uses but may not understand at a high level?

Now let’s create a quick example. In Delphi 2010 let’s create a project where we can witness UML Visualization and get a better understanding of what the feature can do for you.

  • Create a new VCL Forms Application.
  • File|New|VCL Forms Application – Delphi.
  • Click on the Model-View tab besides the Project Manager.
    • This will show the following warning:

Hide image

  • Click the Yes button to continue. NOTE: It will ask you to save the project.
  • This will show the layout of the project on the Model View tab, as below:

Hide image

  • Now click on the reference, click on the DelphiWin32 item, and select the Dialogs item as shown above. If you have been using Delphi for a while then you normally see Dialogs in the Uses clause in a standard VCL forms project.
  • Now using UML Visualization we want to look at the Dialogs unit from a UML perspective and see the relationships between objects. Right-mouse click on the Dialogs item and select the Open Diagram context menu item. In a few short seconds you will start to see a UML representation of the Dialogs unit.

    Before getting too deep into the feature, look at the bottom right hand corner of the content pane and you should see an Overview button. This will give you a standard overview picture of the unit in UML form. This overview can be expanded or configured to your desired look, as shown below:
    Hide image
    Hide image
    Click to see full-sized image

The square found inside the miniature view will allow you to scroll to the desired location in the diagram. In other words, it is the “focus” or “zoom” manager.

  • Now scrolling in the diagram, find the TCommonDialog object. You will notice the relationships through inheritance to TOpenDialog, TPrinterSetupDialog, and TColorDialog, as below:

Hide image
Click to see full-sized image

  • This allows you to better understand the relationships between objects and the hierarchy associated with them.
  • This can be done for any Unit included in the Project including the units created by the developers.

All of this visualization gives you a better insight into the design of the software being created or older software that the developer may not be familiar with.

In the next installment of this series we will focus on the UML features that are included in Delphi 2010 and some of the advanced features like Automatic Document Generation.

Read more on the Blaise Pascal Magazine web site:

Part II: What support for UML is in Delphi 2010?

Part III: Integrated Unit Testing

Part IV: Integrated static analysis: Metrics

Part V: Integrated static analysis: Audits

Part VI: Hello refactoring…

Server Response from: ETNASC03