Skip to content

Extending Delphi 2009 With OpenTools API: Getting Started

Did you know that it is so easy to extend Delphi 2009 IDE?

Delphi 2009 provides a dedicated Open Tools API interface that let you interact and extend the functionality of the Delphi and C++Builder 2009 IDE. "Eric’s Open Tools API FAQ and Resource" is probably the best place to learn about Open Tools API. Eric Berry is well known in Delphi community as author of GExperts extension to all versions of Delphi and also as expert on Tools API itself.

In this post I would like to provide step-by-step instructions how to create a simple menu wizard. The wizard will add an item under Delphi "Help" menu and will just display a "Hello World" message. Nothing fancy, but just a good starting point for adding some more useful functionality.

Create new Delphi "Package" project

  • In Delphi 2009 "File" menu select "Other" and in the "New Items" dialog select a "Package" project from "Delphi Projects" category.
  • Click on "Save All" from "File" menu and give the project "HelloWorldMenuWizard" name.

  • Display "Project Options" dialog clicking on "Options" from "Project" menu and provide a description for a package project in "Description" tab.
    This description will show up in the list of the installed packages.
  • In the "Usage Options" select "Designtime only" as our wizard is only used inside the IDE.

Anything that is installed in the Delphi IDE lives in a package. You can think about a package as a special kind of DLL library. OpenTools API wizards and VCL components are installed into the IDE via packages. By convention a package that is designed to be installed in the IDE contains "Register" global procedure that is called by the IDE when installing a package. For IDE wizards in the body of "Register" routine you should call "RegisterPackageWizard" procedure defined in the "ToolsAPI" unit and pass a reference to a wizard instance that implements "IOTAWizard" interface.

Add an empty unit to the project

After creating a new package project you may think that nothing has happened as there is no default main form in a package project. In order to add code to our wizard we need to add an empty unit from "New Items" dialog.

  • In Delphi 2009 "File" menu select "Other" and in the "New Items" dialog select "Unit" from "Delphi Files" category.
  • Click on "Save All" and give the new unit a name. For example "uMain".
  • Declare "Register" procedure with no parameters in the "interface" section of the unit and provide empty implementation for it. This procedure will be called by the IDE during registering the package.

In the body of the "Register" procedure we need to create an instance of our "Hello World" wizard and pass it to a call to "RegisterPackageWizard" procedure defined in the "ToolsAPI" unit. If you add "ToolsAPI" to the "uses" clause of the unit and try to compile your package project, you will get a compiler error "File not found: ToolsAPI.dcu’".
That is the tricky part. In which library package this unit is defined? It is in "designide.bpl" that is part of Delphi installation. You need to add "designide" to required packages of our package project. We do not have source code for all units in "designide" package, as Delphi is not an open source project, but luckily "ToolsAPI.pas" file is provided in the "source\ToolsAPI" subfolder of Delphi 2009 installation directory.

Add "designide" package to "Required" packages of package project

  • Select "Add to Project" from "Project" menu. This will display "Add" dialog. Select "Requires" tab and click on the "Browse" button. Locate "designide.dcp" from the "lib" folder from the Delphi 2009 installation directory.

Now the Project Manager should look like this:

Now we are ready to add some code to the "uMain" unit to define a class that will act as our menu wizard.
It is more effective to do it in the "implementation" section of our unit. In this way the only functionality exposed to the external world from our wizard is "Register" procedure. The "RegisterPackageWizard" procedure expects "IOTAWizard" parameter, so this is the first interface that our wizard class needs to implement. The "IOTAWizard" wizard interface derives from "IOTANotifier" interface. To avoid implementing all methods defined in both interfaces we need to select an appriopriate class to derive from. "TNotifierObject" is a convinient base class as it already contains empty stub implementations for "IOTANotifier" methods. In the definition of our class we need to explicitly list all interfaces our wizard implements as the IDE will use reflection to find out capabilities of our wizard.

Write code, compile and install

The full source code of our wizard is listed below:

The "GetIDString" method returns a unique name for the wizard that is used internally by Delphi. The "GetName" method returns human-readable name of the wizard. The "GetState" function returns "TWizardState", which a set of two possible enumerated values: "wsEnabled" and "wsChecked". The "Execute" method is called when wizard needs to be executed and the "GetMenuText" returns a string to be displayed in Delphi.

  • Replace the body of the "uMain" unit with the above code. If you do not want to type it in, you can download the whole project from here.
  • Compile wizard project. One of way of doing this is to right-click in the Project Manager on the project and select "Compile".
  • Install wizard in the IDE. Again right-click on the project node in the Project Manager and select "Install" from the context menu.
    If successful you should see confirmation message about installing our wizard. Note that the resulting bpl file is located in different directory as project file.
    On XP this would be: "C:\Documents and Settings\All Users\Documents\RAD Studio\6.0\Bpl\".

Our simple "Hello World" Open Tools API menu wizard has been installed and now you should be able to find a new item under Delphi "Help" menu.

If you click on the new item you should see the following message dialog displayed from the wizard.

If you want to verify that the wizard is installed or you want to uninstall it, you can do this from Component" menu "Installed Packages".

These are real basics. Next time I’m going to implement something more useful:-)

Delphi 2009 Online Resources

Delphi and C++Builder 2009 are considered by many developers that I have met recently the best versions ever of these two great products. There are significant improvements at all levels of product functionality, starting from new Unicode support, new programming languages features, improvements to RTL/VCL, IDE improvements and brand new DataSnap client/server architecture.

Here are some of the Delphi and C++Builder 2009 online resources categorized for your convenience:-)

Embarcadero Update

Delphi 2009 Overview

New IDE Features

Unicode Support

ER/Studio Overview

New Language Features

What’s New in RTL and VCL

DataSnap 2009

Resources

Product pages and trials

Delphi Prism announced at the PDC

The new solution for .NET development from Embarcadero - Delphi Prism - has been announced on the PDC conference in Los Angeles. Delphi Prism is powered by Oxygene compiler technology and will replace both Delphi for .NET and the existing Oxygene product.

Check out a very interesting interview with Marc Hoffman from RemObjects: "Delphi Prism - Visual Studio Pascal For .NET" and the new Delphi Prism in action in this screencast at www.delphi.org.

Delphi Prism supports .NET, Mono on Linux and Cocoa# on MaxOS X and provides full support for the latest .NET technologies plus some very interesting programming language features to support parallel processing, like "future" types, "async" blocks and expressions and "parallel" loops. It also contains Blackfish SQL for Windows and possibility to build DataSnap clients for Delphi DataSnap 2009 servers.

Delphi and C++Builder 2009 in Prague and Bratislava

This week there were two Delphi and C++Builder 2009 launch events in Prague and in Bratislava. In Prague there were 205 developers and in Bratislava around 50. Good numbers of attendees and very interesting questions from the audience.

 

There was an interesting question about the future of native applications on Windows. Check out "wizard behind the curtain" DDJ article for Michael Swindell take on native development. I personally do not expect Microsoft to rewrite Windows in managed code ever.

Anonymous methods and generics were hot topics too. Make sure to visit Barry Kelly and Allen Bauer blogs for more info.

Some people asked about slides for download. Here they are - "What’s New in Delphi 2009".

Automating ER/Studio from Delphi 2009 - Translating build-in macros to Delphi

This is a post for my beloved Grzeniuś:-).

I have change the describtion of my blog to "Delphi Programming" and added "Delphi Programming" category. Watch out TIOBE index! Delphi is strongly rising.

The SDC conference this week was very good and Delphi track was very rich and interesting. In the evening, at the first conference day, during relaxed "Delphi Tips & Tricks" session with Bob Swart and Nick Hodges I have demonstrated automating ER/Studio application in Delphi code from a Delphi VCL Forms application. The first thing is to verify that you have ER/Studio ActiveX VCL wrappers installed on Delphi Tool Palette. The process of importing ER/Studio COM type library into was described in my previous post "Automating ER/Studio from Delphi - Getting Started". The left pane in the main ER/Studio window has got 5 tabs. On the "Macros" tab there is big collection of VBA macros installed "out of the box".

Here is the source of the "Auto-Create New Diagram" macro:

Just drop a "TApplication" component from Delphi Tool Palette on the form and execute the following Delphi code:

The translation is slightly modified. "aEntity" variable stores a reference to the first entity added so it is not neccessary to obtain it again. Executing this code will generate the following ER/Studio diagram

That’s interesting and gives a power of controlling powerful ER/Studio functionality from Delphi code.

Delphi and C++Builder 2009 European Tour

Delphi 2009 and C++Builder 2009 is a very solid release. So is the newest "Death Magnetic" album from Metallica. I’m sitting right now on the plane to Lisbon and feel a little bit like a musician on the tour. Different cities every week. There should be a Delphi 2009 European Tour T-shirt with tour agenda on the back. I’m just one of the many people involved in presenting C++Builder 2009 and Delphi 2009 across the world.
David I and Greg Keller, Embarcadero Chief Evangelists, are probably the most busy ones. Delphi 2009, C++Builder 2009 and ER/Studio (bundled with Delphi "Architect") are very warmly received in every single place I’ve been to. It is so much fun to start the IDE (look how fast it is!) and see all these hardcore developers happy faces, as they see that Delphi and C++Builder are moving forward and provide lots of new features like brand new DataSnap 2009 framework, full Unicode support, enhancements to Project Manager, new Class Explorer, new and enhanced VCL components, native Win32 Ribbon controls for building Office 2007 look-and-feel user interfaces, and powerful new programming language features including Delphi generics, anonymous methods and C++0x extensions.


Delphi 2009 and C++Buider 2009 European Tour:-) Just before the event in Allerod, Denmark

I’m not trying to provide a complete list of Delphi and C++Builder launch events across Europe here. These are just random notes and photos. I have not been to Italy this year where Marco Cantu delivered excellent Delphi seminar. Jon Harrison last week demonstrated Delphi in Budapest. In Russia they have Alexey Kovyazin hosting most, if not all, Russian Delphi events. Same for all German and French speaking countries. English language there? Not neccessarly:-) Matthias Eissing from Germany and Thierry Laborde from France know exactly how to present Delphi and C++Builder 2009:-)

Probably one of the first European Delphi and C++Builder 2009 demonstrations was done by Magnus Flysjö, Swedish Delphi community leader, on the Delphi User Group meeeting in Denmark. Make sure to check out excellent Delphi 2009 wallpaper created by Magnus. David I, while in Latin America, did a virtual keynote for Danish DAPUG programmers.

In London we had Embarcadero VP, Nigel Brown, doing a keynote and Karun Malhotra, from Embarcadero UK office, demonstrating to Delphi and C++Builder developers DatabaseGear Change Manager. Being able to perform a diff on a database scheme and data was really intriguing.


Embarcadero Keynote by Nigel Brown

Delphi event in Poland attracted more then 150 Polish programmers. That was cool. Delphi 2009 launch on the same day as "Death Magnetic" Metallica album. Rafał Kędzierski, BSC Polska Marketing Manager, would probably tell you that there is nothing like Iron Maiden. Andrzej Dąbrowski, consultant from BSC Polska, demonstrated very interesting overview of DatabaseGear products and ER/Studio Developer Edition functionality.


It takes time to register and receive seminar materials


Delphi 2009 launch event in Poland attracted more then 150 Polish programmers.


-)


Rafal and Andrzej from BSC Polska

Below a picture from Delphi and C++Builder launch was organized by Moonsoft, our reseller in Finland.


Delphi 2009 and C++Buider 2009 in Helsinki

Launch events in Amstelveen and Brussels were organized by Barnsten, CodeGear knowledge centre in Benelux. It was very inspiring for me to see Raymond Horsten from CSB, DatabaseGear Benelux knowledge centre, demonstrating ER/Studio. I was making notes as tomorrow in Lisbon it is my first time to demo ER/Studio…


Raymond Horsten from CSB presenting Data Modeling with ER/Studio


Delphi 2009 in Brussels

I’m always happy to go to Denmark. They invented Lego (MindStorms), Metallica (Lars Ulrich), and Delphi (Anders Hejlsberg) over there;-)
With Ole Vestergaard, from Nohau, I’ve been to Allerod and Aarhus demonstrating Delphi 2009 and seeing some familiar faces from previous Delphi events.


Delphi 2009 in Aarhus, Denmark

The Delphi and C++Builder European Tour continues! Tomorrow is Lisbon, and Friday it is Madrid. Next week we have Delphi Product Manager, Nick Hodges, presenting Delphi keynote on the annual SDC Conference in the Netherlands. This is going to be a real Delphi fest with sessions from Bob Swart, Marco Cantu, Jeroen Pluimers, Hadi Harriri and others in Delphi track. The day after SDC there is Delphi event in Stockholm with Nick and Magnus, and in the following week events in Prague and Bratislava.

Delphi and C++Builder users are extremaly passionate and loyal to their beloved tools. At the beginning of a seminar I would typically ask the audience what version of Delphi or C++Builder they are using. I have recently start to ask who was using Turbo Pascal from pre-Delphi era, and it is common to have more then a half of audience coming from Turbo Pascal and Turbo C++ background! There is this slide with product roadmaps and "Turbo Pascal" and "Turbo C++" are there in the first quarter of 2009. I’m looking forward to meeting students at universities some time next year.

Did you know that Niklaus Wirth designed Pascal programming language as a tool for teaching students good programming practices?

My Programming Language (Delphi) Can Do This

joelonsoftware asks on his blog "Can Your Programming Language Do This?". Delphi 2009 introduces support for anonymous methods in Delphi language. Yes, Delphi can do this:-)

For your convinience here is the relevant snippet from Joel’s blog:

-)

Delphi, contrary to JavaScript, is a strongly-typed language. This is the reason you need to define an anonymous method signature.  I think it is a good thing.

Here is the output from a simple console application:

I have my private theory about Joel’s lastname which is "Spolsky". I’m Polish myself and I guees there is some Polish connection here. "Spolsky" sounds like "z Polski" in Polish language, which is "from Poland" but just made more English-looking like.

And make sure you visit "Stack Overflow" for ultimate programmers’ FAQ system.
Creating an account on Stack Overflow is tricky. I had to create a blog account on blogspot server to obtain an openID.

Delphi 2009 and C++Builder 2009 introduce full Unicode support. Here is "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)".

Google Chrome - cool new web browser

Google just released a new web browser called "Chrome". I have downloaded, installed and now using it to type in words of this post. It is ellegant and intriguing. Chrome features new architecture where each browsing tab has its own OS process, which effectively creates a sandboxed environment for every session. I like the way you can dock and undock tabs with smaller and transparent display of a tab being moved. The ideas behind the new browser are very nicely explained in the form of a comic book. Another interesting aspect of Chrome is highly optimized execution environment for JavaScript programs embedded in web pages. The new JavaScript engine is called V8 and uses dynamic native code generation for faster execution times, what is discussed on the Chromium Blog and in the design docs. Google Chrome is open source under a permissive BSD license. That is really cool. 5 minute interview with some of the Chrome creators is on youtube.

My Delphi 2009 Top 5

What do you like the most in the new Delphi 2009? There is an interesting thread on forum.barnsten.com. Here is my personal Top 5

  1. Full Unicode support throughout the product - from the new UnicodeString type in the compiler, throughout RTL, VCL and the whole IDE
  2. New Language Features in Delphi language - generics and anonymous methods
  3. New DataSnap architecture, based on DBX, for lightweight, client/server applications
  4. Improvements in the VCL including new Ribbon controls. A bunch of brand new VCL components, like TButtonedEdit, TBalloonHint, TCategoryPanelGroup, and improvements to existing ones, like new "Alignment" property in TEdit (finally!), support for images in TButton and many others
  5. Improvements in the IDE: new Class Explorer, new Resource Manager, Named Build Configurations and Option Sets, more flexible Project Manager.

If you want to see new Delphi 2009 features live, make sure to register for "Take a First look at Delphi 2009 and C++ Builder 2009 - Database Development - Beyond the IDE" workshops:

Polska Premiera Delphi 2009 i C++Builder 2009 - Warszawa, 12 września

Delphi 2009 i C++Builder 2009 już są dostępne! Jeśli interesujesz się programowaniem, a szczególnie jeżeli programujesz w Delphi albo w C++, nie możesz przegapić piątku, 12 września - BSC Polska organizuje premierę najnowszej wersji Delphi i C++Buildera!Na stronie http://www.codegear.pl/seminaria/delphi2009/ można zarejestrować się na bezpłatną konferencję, która odbędzie się w Hotelu Lord w Warszawie, Al. Krakowska 218.Od 25 sierpnia rozpoczął się cykl webinariów omawiających szczegóły nowego Delphi i C++Buildera. Szczegółowa agenda jest dostępna tu: http://dn.codegear.com/article/38478Delphi 2009 i C++Builder 2009 zawierają wiele nowych cech, z czego najważniejsze to:

  • pełna obsługa Unicode w kompilatorze, wizualnej bibliotece komponentów (VCL) i w zintegrowanym środowisku programistycznym (IDE)
  • nowe elementy w języku programowania Delphi i C++
  • udoskonalona architektura DataSnap do budowania wielowarstwowych aplikacji bazodanowych

Wielu programistów to również czytelnicy literatury science-fiction i fani muzyki heavy metal. Czyż to nie jest dobry znak, że w dniu premiery Delphi w Polsce, 12 września 2008, grupa Metallica wydaje swoją najnowszą, długo oczekiwaną płytę Death Magnetic? Jestem pewien, że najnowsza wersja Delphi 2009 okaże się prawdziwym kamieniem milowym, czego również można się spodziewać po Metallice.Jeżeli cały czas słuchasz "Master Of Puppets" i programujesz w Delphi 7, to najwyższy czas się "zapgrejdować":-)

Bad Behavior has blocked 168 access attempts in the last 7 days.

Close