Tuesday, October 6, 2020

Deleaker: Advanced Memory Leak Detection for Delphi and RAD Studio

Beginning with RAD Studio 2006, Delphi, and RAD Studio in general, greatly benefited from the addition of Fast Memory Manager, or FastMM. And one of the truly welcome additions was the global variable ReportMemoryLeaksUponShutdown, which, when set to True and a small block memory leak is detected upon your application’s shutdown, displays a dialog box that identifies what was left behind. It doesn’t identify where the leak occurred, however, only that it happened.

FastMM continues to be available in RAD Studio, and you should consider downloading the full version from SourceForge (http://sourceforge.net/projects/fastmm/) to realize the full potential of FastMM, which includes much more than just memory leak detection, including enabling the generation of a stack trace, which may provide additional information about where the leak occurred.

That said, as far as memory leaks go, sometimes you need more. Which brings me to Deleaker.

I recently had the opportunity to try out Deleaker from Softantics in my Delphi applications, and I was impressed. Deleaker is a memory leak detection tool for Windows 32-bit and 64-bit applications. It can integrate with RAD studio and Visual Studio (as well as Qt Creator), and also supports a command line interface that permits you to include Deleaker as part of your continuous integration (CI) process.

In the past I’ve relied on RAD Studio’s ReportMemoryLeaksOnShutdow to identify memory leaks, but that option only tells you that you have leaks as well as how much memory was leaked. By comparison, Deleaker, when property configured, does an amazing job of identifying the source of the leak, going so far as to identify unit names and even line numbers where the leak originated. It can also find leaks in any module, for example, WinAPI functions such as CoTaskMemAlloc. FastMM cannot find that kind of leak.

Installation is simple, and after installation a new menu item, Deleaker, appears in RAD Studio’s main menu. From that menu you can enable Deleaker for all of your applications, configure Deleaker’s options, and open the Deleaker Console.

When the installation of Deleaker is complete it displays a help file that explains how to configure RAD Studio to generate the information Deleaker needs in order to serve you. (In short, you need to turn on your compiler and linker debugging options.) This help file, which can also be displayed any time you need it from the Deleaker Console, is well written and easy to follow, and the setup in RAD Studio only requires a few easy steps.

When Deleaker is enabled, and you are running your application with debugging enabled, the Deleaker Console launches when you shutdown your application. If no leak is detected, it reports that. Alternatively, if a leak is detected, Deleaker can often identify the unit name and line number where the leak likely originated. If the leak is related to a Delphi object, Deleaker will report what class of object produced the leak. This can save you hours of time scrutinizing your code for mishandled resources.

You can also display the Deleaker Console while your application is running. This permits you to take one or more snapshots of your memory usage, so you can see what’s going on while your application is still running. The Deleaker Console also lets you compare snapshots, which permits you to see changes in memory usage over time.

The types of leaks that Deleaker can detect are extensive. Here is a list, taken from the Deleaker Help file:

Memory: memory blocks allocated by heap functions, virtual memory, OLE memory:
BSTR, SAFEARRAY, etc
GDI: HBITMAP, HDC, HPEN, etc.
User32: HICON, HCURSOR, etc.
Handles: file handles, events, mutexes, etc.
FileView: views of file mappings
ActCtxCookie: cookies of activation contexts
Fiber: fibers made by CreateFiber, etc.
CriticalSection: critical sections ((if one has called InitializeCriticalSection but
forgotten to call DeleteCriticalSection)
EnvironmentString: ANSI and UNICODE environment strings
FlsSlot: fls slots
TlsSlot: tls slots
Atom: atoms.

During development, when Deleaker is enabled, you need to run your application with debugging enabled. However, it is also possible to use Deleaker with an application that is running outside of Delphi. For example, on a machine on which Delphi is not installed. Simply copy the Deleaker Console onto the machine, and then run it (Microsoft’s .NET Framework 3.5 might need to be installed). From there you can either launch your application from the Deleaker Console, or even attach to your already running application.

You can check out Deleaker free for 14 days, after which you can buy a license. Available licenses include a home license (for personal use), a single developer license, and site licenses.

You can find the Deleaker home page at https://www.deleaker.com/

Copyright © 2020. All Rights Reserved.

Wednesday, February 12, 2020

25 Years of Communicating about Delphi

Delphi turns 25 this Friday, and I’ve been fortunate to have had a front row seat. And, in addition to being a life-long database application developer, I’ve also made a career out of sharing information about software development, through books, magazine articles, conference talks, and training seminars. In this post I want to reflect back on those heady days when Delphi first came on the scene. For those who’ve been with me on this journey, thank you. For those of you who are too young to have had this pleasure, may your careers be as rich and as rewarding as it has been for those who’ve been there the whole time.

I was a frequent member of the Borland Conference (BorCon) advisory board, and that exposed me to Delphi early in its development stage. At the time I was an associate editor and columnist for Paradox Informant Magazine, and Delphi sounded like it was going to be the compiler that we Paradox developers had been waiting for.

And it was. As my longtime friend Ann Lynnworth predicted, Delphi reduced Paradox to a mere file format. It was clear to me that Delphi was going to be a really big deal. As a result, in the pre-release times I took two steps to join the Delphi community as a charter member. I committed to Informant Group publisher Mitch Koulouris to write a monthly column for his new Delphi Informant Magazine. My column, called DBNavigator (after the Delphi component), focused primarily on database development and related issues. In that first issue I described using the Borland Database Engine from within Delphi to work with Paradox and Dbase tables. That was the first of 42 consecutive issues in which my column appeared, though I continued to be a regular contributor for the remaining years of publication.



The front cover of the premiere issue of Delphi Informant Magazine, published in May of 1995

My second commitment was to Softbite International president Kevin Smith, to write and present a two-day Delphi course if he would take it out on tour. I had been working with Softbite for some years, and was a presenter on the Paradox 5 for Windows World Tour, and wrote the material for, and presented, on the Paradox 7 for Windows World Tour. He agreed, and this new 24 city tour was known as the Delphi World Tour. It began in Columbus, Ohio on July 6th of 1995. I taught that first stop, as well as about 12 others. I believe there were two other presenters, one of them being the venerable Bill Todd. If there was another, I can’t remember who it was. They (or he) covered the remaining cities.



An ad for the original Delphi World Tour appearing in the July 1995 issue of Delphi Informant

Despite my principal work being as a Delphi developer, I continued to write and present the Delphi World Tours (the final being the Delphi 5 World Tour), and followed that with Delphi Development Seminars in conjunction with Informant Communication Group (one year only), several years of the Borland Developer Days (Europe, in conjunction with Desktop Associates), and then Delphi Developer Days, which I started with my wife, Loy Anderson. Delphi Developer Days ran from 2001 (where the first stop on the tour, Arlington, Virginia, had to be cancelled after the 9/11 attacks due to the closing of Metro underground that ran past the Pentagon and the number of government attendees, whose priorities changed after that awful event) and continued through 2017.

We expanded Delphi Developer Days in 2009 by added a second presenter, which gave me the opportunity to work with four of the top Delphi professionals, all Spirit of Delphi recipients: Marco Cantú, Bob Swart, Ray Konopka, and Nick Hodges. Thanks, guys. It was a great pleasure.

During the past 25 years I have written about and/or trained developers on every version of Delphi (including the notorious .NET only Delphi 8), and as you might imagine, I have acquired a museum-like collection of software. One of my favorites, shown here, is my original, shrink-wrapped copy of Delphi Client/Server.



A shrink-wrapped copy of the original Delphi Client/Server

I have a lot of stories that I could share about Delphi, but I think I’ll leave those for another time. I mean, there’s a real danger here. I know myself pretty well, and once I got started, I’d probably have to write an entire book, and I just don’t have the time for that right now, my being committed to a new startup.

But a particular observation comes to mind. To quote the immortal Grateful Dead, and in respect for David Intersimone’s penchant for wearing tie-dye t-shirts, I have to say “What a long strange trip it’s been.”

Let me conclude with an observation and a positive thought. Delphi is still going strong, and the latest version, Delphi Rio 10.3.3, is the best yet. So, Cheers! Here’s to the next 25 years.

Copyright © 2020. All Rights Reserved.

Thursday, November 21, 2019

Exploring the Navigation Toolbar


There have been a few times when a major feature of the IDE has gone largely unnoticed, but they are rare. Nonetheless, it has happened again in a recent release of Delphi. Since the release of Delphi XE8, Delphi's IDE now sports some new informational and navigational features that are big, really big. And, so far, most Delphi developers that I've demonstrated these to have been surprised, and shocked, and have immediately changed the way they work with units while in Delphi's editor. This feature is call the Navigation toolbar, and it's easy to miss.

The Navigation toolbar appears just above the code editor when the Code tab is selected in the designer. The Navigation toolbar is shown in the following figure. There's not much to it, is there. This is why it's easy to miss.


The Navigation toolbar is used both for information, as well as navigation and searching. You can determine which unit is being displayed in the code editor by the text that appears on the currently selected tab, and that's been a feature of the IDE since Galileo was originally released with C++ Builder and Delphi 8 (and, the tabs are not part of the Navigation toolbar, The Navigation toolbar is only the thin slice beneath the tabs). When the insertion point (the current position of the cursor in the editor) is within a type declaration or a type implementation, the type appears in the Types combo box. This is shown in the following figure, where the insertion point is in the TUserData declaration of the Win.UserData unit of the UserData project.


If your insertion point is in the implementation of a method, the class or record appears in the Type combo box, and the method appears in the Methods combo box.



If your insertion point is inside the implementation of a pure function or procedure, the Type combo box will be empty, and the procedure or function name will appear in the Methods combo box, as shown in the following figure.



While serving to inform you where your insertion point is located, you can also use the Type and Method combo boxes to navigate your units, and this is where the real advantage of the Navigation toolbar begins to emerge.
Again, with the Win.UserData unit selected, I can easily move between the various types declared in this unit by dropping down the Type combo box, as shown in following figure.



If the selected type is a class or record, you can further navigate to a particular method of that type by dropping down the Method combo box.



While you can easily do this with your mouse, both the Type combo box and Method combo box dropdowns can also be accessed using key combinations. For the Type combo box, press Ctrl-Alt-N + Ctrl-Alt-T. That is, hold down the Ctrl and Alt keys while pressing N, and then release and then hold down the Ctrl and Alt keys while pressing T, and then release. Access the Method combo box dropdown by pressing Ctrl-Alt-N + Ctrl-Alt-P.

While I love the Type and Method combo boxes, my favorite feature of the Navigation toolbar is the File Sections combo box. This combo box permits you to instantly navigate to a specific section of the current unit, a feature that you will use over and over. This combo box, shown in the following figure, can also be accessed using the Ctrl-Alt-N + Ctrl-Alt-S key combination.



To the left of the File Sections combo box you will find the Used Units combo box. This combo box displays all of the units used by the current unit (both interface and implementation section uses clauses), and permits you to easily open and navigate to any of those units (assuming that the source code is available). The Used Units combo box, shown in the following figure, can also be displayed by pressing the Ctrl-Alt-N + Ctrl-Alt-U key combination.



There is one more feature available from the Navigation toolbar. To the right of the Methods combo box you will find the Project Symbol Search feature, which is represented by a magnifying glass icon.

Click on the magnifying glass icon, or press Ctrl-Alt-N + Ctrl-Alt-F, and the Navigation toolbar will display a search window and an associated Results list box. As you type characters, all symbols within the current project that include those consecutive characters that you've typed will appear in the Results list box (in the following figure I have typed btnc). If you then click on, or select and press the Enter key, any of the results, you instantly navigate to the selected unit and symbol declaration.



That's it for the Navigation toolbar. However, before we leave this section I want to point out the down arrow icon that appears at the upper-right corner of the preceding figure. You probably already know about this one, since it's been in the product a long time. But in case you do not, let me point out that this dropdown displays all open units, in alphabetical order. This can be very handy when you want to move to an open unit, but you have so many units opened that only a subset of the open units appear in the tabs above the editor pane. To use this feature, click on the down-arrow icon, and then select the unit to which you want to navigate from the displayed dropdown list.

Note: Notice that all of these key combinations used by the Navigation toolbar start with Ctrl-Alt-N (for navigation) while the second key press is almost predictable, as in Ctrl-Alt-T for type, Ctrl-Alt-S for section, Ctrl-Alt-U for Used Units. Only the Methods combo box dropdown key combination is awkward, using Ctrl-Alt-P, but in that case I must assume the P stands for procedure.


Copyright (c) 2017-2019 Cary Jensen. All Rights Reserved.

Monday, November 26, 2018

My Advice: Monitor Your Health


Permit me to share a bit of unsolicited advice. There are two parts to it. First, get an annual physical from a health professional. Second, if you sense an unusual change in your health, seek a physician’s advice.

Getting an annual checkup, with the accompanying tests (physical examination, blood work) permits you to establish baseline measurements about your health, which can be useful in identifying trends that may require additional follow-up. Seeking help when you experience an unexpected change (increased pain, odd swelling, etc.) can potentially identify a problem while it is still in an early stage.

I give this advice because I have seen family and friends skip annual checkups (“I’m very healthy. I don’t need to see a doctor” or “I hate going to the doctor”), or ignore warning signs. In one heartbreaking case for me, this lead to the untimely, and completely avoidable death of a wonderful individual, depriving us all, permanently, of the joy of their presence.

Consider my situation. I get annual checkups, and during a recent examination my PSA (prostate specific antigen) blood test showed an increase in PSA. A subsequent test confirmed this, and I had a biopsy to determine the cause. It was cancer. Due to the type of cancer, and my age, I had two options: Radiation and surgery. I opted for surgery, and the operation was performed at the end of February this year.

Based on the post-surgical lab work on the removed tissue, and the first three post-op PSA tests, it looked like I was cancer-free. This changed earlier this month, as I now have a detectable PSA reading, which means that the cancer is still present. Importantly, we reacted quickly to the original diagnosis, and we are moving aggressively to address this new information. By doing so, we are giving me to best opportunity to overcome this ailment.

I’m sharing my story, and offering my advice, in hope that you monitor your health, providing you with the opportunity to address and overcome any obstacles before they get out of control, to the benefit of you and your loved ones.

So, please, if at all possible, adopt a regime of annual physicals. And if you notice something wrong, or out of the ordinary, get it checked out.

Thursday, October 4, 2018

Cary Jensen is available to help your Delphi team


Are you looking for help with your Delphi applications and/or your Delphi team? I will be available for contract work starting in mid-November 2018.

Over the past 30 years, I have primarily been a software developer specializing in database applications, but I am also the author of more than 25 books on software, and have written over 100 courses on software development. I was the author of, and principle trainer on the original Delphi World Tour in 1995, continuing until it concluded in 1999. On a related note, I am the founder of Delphi Developer Days, which began in 2001 and continues to this day.

On the more technical level, I have a Ph.D. in Engineering Psychology, specializing in human/computer interaction. My studies emphasized an analytical approach, with a heavy dose of statistics.

Due to my commitments to writing, Delphi Developer Days, and existing clients, I am looking for a part-time opportunity, where I can provide from one to three weeks of support each month.

I love to travel, so I am particularly interested in opportunities that include onsite work almost anywhere in the world, but I am open to some remote support.

I can help in the following areas:
• Application architecture
• Object-oriented development
• Legacy application migration to recent versions of Delphi
• Application refactoring to improve maintenance and support
• Class and component creation
• Evaluating employee candidates
• Developer training
• Developer mentoring
• Class and component creation
• Software documentation
• General business consulting

If you are interested in learning more about how I can help your organization, please contact me at the following email address: cary at jensendatasystems.com.

Monday, September 3, 2018

Sign Up for the Delphi Community Edition Boot Camp Today


If you are new to Delphi, the cross-platform, native compiling rapid application development (RAD) tool from Embarcadero Technologies, or know someone who is, there’s an upcoming event that you need to know about. It is the Delphi Community Edition (CE) Boot Camp.

The Delphi CE Boot Camp is a series of lectures designed to introduce you to developing world-class applications using Delphi. Beginning on September 3rd, and continuing for a total of 8 weeks, each week introduces you to a different aspect of Delphi development, from building the user interface to compiling applications for iOS and Android devices. Week 1 begins with an introduction to the Delphi language (object-oriented Pascal), presented by Delphi guru and Delphi Product Manager Marco Cantú.

The Delphi CE Boot Camp is free for everyone. To attend, use the following link to get started: https://www.embarcaderoacademy.com/p/the-delphi-ce-bootcamp-2018.

The lessons for each week will become available on the date listed for each topic area. You can watch the lessons any time you want once they are published. In addition, some lessons are followed up with live question and answer sessions with the instructor. See the Boot Camp site for details.

Don’t have a current copy of Delphi. No problem. So long as you meet the requirements, you can download and use the free Delphi Community Edition which became available this past July. The Delphi Community Edition is a full featured Professional Edition designed to get you up and running. To learn more about the Delphi Community Edition, along with its terms of use, visit https://www.embarcadero.com/products/delphi/starter/free-download.

If you are a database developer, you will want to attend my course on database development with Delphi. My lessons will become available on September 24th.

If you have colleagues who are new to Delphi, please be sure to share this information with them. There’s never been a better time to get started with the best native compiler for building applications for Windows, OSX, iOS, Android, and Linux.

Tuesday, June 13, 2017

Announcing Delphi Developer Days 2017 Special Edition Database Workshop

I am pleased to announce that registration is now open for Delphi Developer Days 2017 Special Edition Database Workshop with Bob Swart and me, Cary Jensen, which will be held this fall in the U.S. and Europe.

Unlike our traditional Delphi Developer Days events, which include a broad range of topics, this workshop focuses exclusively on database development. It begins with a detailed look at connecting to data and configuring FireDAC, and continues with a look at some of FireDAC’s more advanced features, including Array DML, the SQL command preprocessor, and cached updates.

The workshop continues with an in-depth discussion of multi-tier development. Topics include creating DataSnap servers and using Embarcadero’s RAD Server. Here you will learn how to access your data from mobile applications, how to support both Delphi and non-Delphi clients using REST (REpresentational State Transfer), and how to create RAD Server microservices with Delphi.

Both days of this workshop are taught jointly by me and Bob. You are encouraged (though not required) to bring a laptop in order to follow along with the provided code samples.

Each attendee will receive a Delphi Developer Days course book, which includes a special edition of my latest book Delphi in Depth: FireDAC, along with material on DataSnap, mobile development, and RAD Server written by Bob (Dr.Bob) Swart.

Here are the cities and dates for this fall tour:
Chicago, 25-26 September 2017
Antwerp, Belgium, 9-10 October 2017
Frankfurt, Germany, 27-28 November 2017

In addition to the course book, attendees also receive lunch on each day and all code samples covered during the workshop. Due to the nature of this workshop format, seating is limited. Register now to save your place in this special edition database workshop and receive a substantial discount for early registration. For more information, visit http://www.DelphiDeveloperDays.com.

The Delphi Developer Days 2017 Special Edition Database Workshop is taught in English.

Note that we will return with the traditional Delphi Developer Days event in the spring of 2018, where we present both joint as well as separate sessions on a wide variety of Delphi topics.