- An Error at Run-Time due to the Database Connection Left Open at Design-Time
- Fun With Testing DateUtils.pas #1
- Random Thoughts on the Passing Scene #149
- Two more RAD Studio/Delphi/C++Builder/Delphi Prism webinars this month
- Selecting Delphi's TListView Item When the Item's Checkbox is Checked
- Webinar: Migrating Legacy Apps to Unicode-enabled Delphi 2010
- Adding Custom Properties to Delphi Forms; Overriding the Create Constructor
- Delphi 2010 Handbook on Amazon, Developer Network
- Fun Phone Calls with Delphi Prism
- Webinar: RAD/AJAX-based Web Application Development using RAD Studio 2010
- Delphi tutorial video: Advanced REST development with AJAX and databases
- Display Custom TTreeView Item Hints
News, Blogs, and Tips
An Error at Run-Time due to the Database Connection Left Open at Design-Time
in Delphi Database Development :: No matter how much I (guess this refers to all of you) try not to leave the Connected property to true before building for the last time - in most cases I simply forget to close the connection before saving and closing the project.
Read the full article to learn about An Error at Run-Time due to the Database Connection Left Open at Design-Time.
Related:
- Constructing the Database Connection String Dynamically at Run Time
- Enumerating available SQL Servers. Retrieving databases on a SQL Server.
- Access / SQL Server Database Explorer with full Delphi source code
An Error at Run-Time due to the Database Connection Left Open at Design-Time originally appeared on About.com Delphi Programming on Thursday, March 11th, 2010 at 03:00:29.
Fun With Testing DateUtils.pas #1
Okay, so I’m a Development Manager. My job is to see to the health, welfare, productivity, effectiveness, and proper tasking of a big chunk of the RAD Studio development team. I share these duties with the excellent and capable Mike Devery. I mainly manage the guys that work on the IDE, the RTL, and the frameworks. I do things like make sure they are working on the right thing via our SCRUM interations, that they have good machines, nice chairs, vacations when they want them, the right keyboard, etc. I manage the development process in that we on the “War Team” spend a lot of time triaging bugs, managing and defining requirements, tracking progress, finding better ways to write better code – you know, development manager stuff.
But, like all good development managers, my heart really is in coding. And I don’t do much of that anymore. So I’ve tried to keep my fingers in things by taking on some small development tasks where I can keep my skills up, stimulate my brain in that way, and not cause too much damage.
What better way to do that than to write unit tests? I’m a bit weird in that I actually like to write unit tests. I find them challenging and enjoy the “puzzle solving” aspect of it. I like to try to find corner and edge cases where the tests might fail. I like knowing that ever test I write means less work down the road because any regressions will be found sooner – hopefully immediately. And I can write tests to my hearts content without worrying about breaking the product.
So I started in on DateUtils.pas. This is a pretty cool unit with a lot of good functionality, and it’s ripe for expanding on our unit tests. It was written a while ago, and its unit test coverage wasn’t where it should be. So in my “spare time” (hehe….) I’ve been writing unit tests for the routines in that unit. It’s been pretty fun, and I think, too, that it’s been illustrative of how beneficial unit testing can be. So I thought I’d write a series of blog posts about it, and this is the first one.
So, one of the first things I realized was that I needed to be able to generate dates. Now, I realized that you don’t want that many non-deterministic tests (or maybe you don’t want any at all – it depends). But I need to be sure that many of the DateUtils.pas routines can pass with any date. So I wrote the following routine to generate a legitimate but random date:
/// <summary> /// This creates a random, valid date from year 1 to aYearRange /// </summary> function CreateRandomDate(aMakeItLeapYear: Boolean = False; aYearRange: Word = 2500): TDateTime; var AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word; begin AYear := Random(aYearRange) + 1; if (not IsLeapYear(AYear)) and (aMakeItLeapYear) then begin repeat Inc(AYear); until IsLeapYear(AYear); end; AMonth := Random(MonthsPerYear) + 1; if IsLeapYear(AYear) and (AMonth = 2) then begin ADay := Random(29) + 1; end else begin ADay := Random(28) + 1; end; AHour := Random(HoursPerDay) - 1; AMinute := Random(MinsPerHour) - 1; ASecond := Random(SecsPerMin) - 1; AMilliSecond := Random(MSecsPerSec); Result := EncodeDateTime(AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond); end;Now I’ll bet that you guys can come up with a better algorithm, but this works just fine for testing purposes and is pretty clear in what it does. I use it to test, say, 1000 random dates against a routine that takes a Date as a parameter. (By the way, it uses some constants from SysUtils and from DateUtils.) I mix that in with tests that used constant dates every time. I debated whether to do the random date thing (if a test fails, you can’t necessarily reproduce it), but I decided in favor of it because I’ll make sure all the tests clearly report the date that was failing, and because I wanted to test to make sure that any date would be handled correctly, and you simply can’t do that with a limited, fixed set of dates. Constantly running a large set of random dates is as close as you can come to testing “every” date.
Another thing that I knew I’d need was to generate to do date testing is valid “Leap Days’”, that is, a valid February 29 date. When you unit test, you are constantly looking for corner cases, and Leap Days are a corner case for dates. Naturally, I’ll utilize CreateRandomDate to help out:
function GetRandomLeapDay: TDate; begin Result := DateOf(CreateRandomDate(True)); Result := RecodeDate(Result, YearOf(Result), 2, 29); end;So, now I can generate random dates, and easily create corner case LeapDays.
I’ll probably also eventually add a GenerateRandomTime routine as well.
That’s it for now – next time I’ll talk about the basics of how I got tests up and running. By the way, I am using DUnit. We use DUnit extensively internally.
Random Thoughts on the Passing Scene #149
- If you are a registered user of Delphi 2010, you can now download a digital copy of Marco Cantu’s new book, Delphi 2010 Handbook. (From Marco’s Site: “The book covers all the new features of Delphi 2010 for Win32, from Extended RTTI to new IDE features, from Windows 7 support to the improved DataSnap architecture. This is a brand new book, there is no overlapping material with the Delphi 2007 Handbook and Delphi 2009 Handbook (which you can consider buying along with this book in printed or electronic format).”) I think you all know by now how great Marco’s stuff is. You can also order a hard-copy of the book as well from Marco’s site. (Marco now is using CreateSpace as his publishing center. The CreateSpace guys are actually here in our current building – I play basketball with a couple of the guys that work there….)
- Anders apparently can’t control himself and has put a few more items up for auction, including an autographed by Allen Bauer copy of Delphi 1.
- Michael Swindell sent me this link today: The Secret Origin of Windows or as he called it “How Turbo Pascal Shaped Windows 1.0”. Read and enjoy.
Two more RAD Studio/Delphi/C++Builder/Delphi Prism webinars this month
March has been a big month for development webinars on EDN. We have two more webinars to go before we are finished:
- March 18: RAD/AJAX-based Web Application Development using Delphi and RAD Studio 2010 with David I.
- March 24: Migrating legacy applications to Unicode-enabled using Delphi 2010 with Cary Jensen
The other webinars that have recently taken place include:
- RESTful Web Services with Delphi and RAD Studio 2010 with Marco Cantu
- The Secrets of Rapid, Visual, C++ Application Development with David I.
- .NET and Cross-Platform Mono Applications with Delphi Prism with David I.
- Multi-tier applications using DataSnap with David I.
Check out the RAD Studio in Action page for all the white papers, videos, articles, and webinar replay links. You will learn from some of the top programming experts including Brian Long, Bob Swart and Marco Cantu. You’ll find the page at http://www.embarcadero.com/rad-in-action.
Selecting Delphi's TListView Item When the Item's Checkbox is Checked
You will notice that checking or unchecking the item in a list view will not change the selected item - the item that gets checked will not get selected.
Read the full article to learn how to Programmatically Select a TListView Item on Item Check / Uncheck
Related:
- How to Implement the On Item Checked Event for the TListView Delphi control
- Use Custom Check Box Images for a ListView
- Force TListView's Edit Mode using a Keyboard Shortcut
Selecting Delphi's TListView Item When the Item's Checkbox is Checked originally appeared on About.com Delphi Programming on Tuesday, March 9th, 2010 at 06:29:01.
Adding Custom Properties to Delphi Forms; Overriding the Create Constructor
in Delphi Tips :: If you need to add a custom property to a form and have it initialized *before* the OnCreate event, you will need to override the form's constructor.
Read the full article to learn about Adding Custom Properties to Delphi Forms; Overriding the Create Constructor.
Related:
Adding Custom Properties to Delphi Forms; Overriding the Create Constructor originally appeared on About.com Delphi Programming on Monday, March 8th, 2010 at 02:00:40.
Delphi 2010 Handbook on Amazon, Developer Network
The printed edition of my book is now available on Amazon, at http://www.amazon.com/Delphi-2010-Handbook-Features-upgrading/dp/1450597262/. The book is still also on CreateSpace (which is the actual print-on-demand company), but buying it from Amazon you can take advantage of their lower-cost shipping and handling. Notice that this is Amazon US only, these books rarely show up on international versions of Amazon.
At the same time Embarcadero (who bought an open license from me) has made the PDF available now on their Embarcadero Developer Network, free for registered users of Delphi 2010 (in its various incarnations). The direct link to the page which will check your permissions is http://cc.embarcadero.com/item/27613. As you'll see, the book has half a dozen ads, from companies that helped making the free dowanload for registered users possible (adding some to the money offered by Embarcadero).
Finally, I wanted to thank all the developers who attended my online webinar on REST on Wednesday. It was tough (particularly getting up at am), but certainly worth.
Fun Phone Calls with Delphi Prism
I was talking with a customer yesterday. It was a pretty typical conversation – they have a big investment in Delphi, with hundreds of thousands of lines of code. They had built a major application for a major business using DataSnap and dbGo (formerly ADOExpress). They had started to build some new web systems with C#, and were trying to figure out where to go next with their existing code base.
Phone calls like this are really fun now. You know why? Delphi Prism, that’s why. These guys were looking at renewing their RAD Studio Software Assurance, and so they have full access to Delphi Prism. They were using C#, but when they started hearing about what Prism could do for them, they were quite interested. They loved the notion of being able to write ASP.NET applications that talk to their DataSnap servers, and they loved the notion of being able to use Delphi syntax for all of their .Net needs.
And Delphi Prism can do that. It can meet all of your .Net needs. The Delphi Prism team at RemObjects have done an incredible job with the language. You give up absolutely nothing if you choose Delphi Prism with the Oxygene language, and you gain a lot over competing languages. Prism was designed from the ground up with .Net in mind. There is nothing in the .Net world the Oxygene language can’t do. And there is a lot in the language that other .Net languages can’t do. LINQ, Generics, Anonymous methods, delegates, attributes, futures, nullable types, sets, anonymous types – its all there. And the cool part is that the language keeps moving forward, with powerful new features like direct support for Aspect Oriented Programming and Expression types. And all with our beloved begin…end and the rest of the familiar Delphi syntax. You want to build a Silverlight application? No problem. Need to develop for Linux with Mono? The Mac? We have you covered. Want to develop with Prism /on/ the Mac and /on/ Linux? We’ll have you covered there, too, with the next release. You give up nothing and gain a lot. Wait, I already said that. But I guess it bears repeating.
But the team is not resting on their laurels – they are pressing forward. The upcoming release will support the new Visual Studio 2010. It will be integrated into the MonoDevelop platform. It will provide full language support for the .Net 4.0 platform, including support for dynamic language structures, expression types, a cool new Extension Method syntax, and more. (And while they are at it, they’ve even developed a Delphi-based .Net Scripting tool. And it’s free, too. How cool is that?)
It’s not overstating the case to say that Prism is out in front of the pack with regard to supporting .Net. Have I mentioned that you give up nothing and gain a lot if you use Prism?
If you haven’t given Delphi Prism a look, you should. You can download a trial and give it a whirl. You can peruse the documentation online. Need information on how to get started? Check out the Prism Primer.
P.S. The team that brings you Delphi Prism also develops powerful Delphi tools like DataAbstract and the RemObjects SDK. well worth a look. RemObjects is also moving into the area of Mac/OS X development. Nothing seems to stop moving with those guys, and everything moves in a very cool direction.
Webinar: RAD/AJAX-based Web Application Development using RAD Studio 2010
Delphi tutorial video: Advanced REST development with AJAX and databases
Display Custom TTreeView Item Hints
in Delphi VCL ::
The TTreeView Delphi control wraps the Windows tree view control. TTreeView is comonly used when a hierarhical structure needs to be displayed to the user.
To display different hints for every node in a tree view, you need to change the Hint property of the TTreeView control depending on the item the mouse is over.
Read the full article to learn how to Display Custom TTreeView Item Hints.
Related:
- Disable Automatic Hint Feature for the TTreeView
- Displaying XML (RSS Feed) Data in a TreeView
- How to Display "Bold" Items in the TTreeView
Display Custom TTreeView Item Hints originally appeared on About.com Delphi Programming on Friday, March 5th, 2010 at 02:00:07.
Random Thoughts on the Passing Scene #148
- The Haitian Relief Auction is wrapping up, and there are still some good deals to be had. My favorite out there right now is the “Your name (and picture) in the RAD Studio Easter Egg”. The bidding has gone above $100, so the winning bidder will have their picture included as well. I can tell you that it is fun to have your name in there, and so bid away! Anders highlights a few of the final items, including some autographed books. I think in the end, you all will have contributed well north of $20,000 to the folk in Haiti. Well done and thank you! I should also say thanks to Anders Hejlsberg, Danny Thorpe, Charlie Calvert, and others that took the time and effort to sign and mail back a number of items, as well as to the team members here in Scotts Valley that generously donated a number of their personal copies of software. Well done!
- I was noticing the other day that my Tom Bihn backpack is still pretty much as good as new. I cannot find any way in which it is not in the same condition as the day I bought it. Seriously. I blogged about it when I got it two and a half years ago, and I’m happy to report that reports of their excellent durability are true. I use it every day, take it every where, shove it in my trunk every day on the way to and from work, and it appears to me to be as good as the day I bought it. I am not kidding — this thing is in tip-top shape. I can’t recommend them enough. Seriously excellent product.
- If you are going to be at the Enterprise DataWorld Conference in San Francisco, March 14-18, then do stop by our booth or catch Jason Tiret, our Director of Modeling and Design Solutions, give a talk.
- I absolutely love this site: PleaseRobMe.com Apparently there are a number of different applications for the iPhone, Android, Blackberry, etc., that will make an entry on Twitter based on your location – for instance, FourSquare.com. So if you are at Starbucks, Twitter will report “I am at the Starbucks at 123 Main Street” or whatever. Well, this data is harvestable from Twitter, and so the PleaseRobMe folks are pulling it all together. Note: I am in no way advocating robbery or burglary. I am, however, laughing at what those guys are doing.
Delphi tutorial video: Developing a REST Web server and working with DataSnap
Disable Automatic Hint Feature for the TTreeView
in Delphi TIPS :: By Windows design, when you hover your mouse over an item, a hint (tooltip) window appears containing the title of the item under the mouse cursor, if the entire title is not currently visible.
Sometimes, you might want to disable such tree view behavior in order to show, for example, custom hints for every tree node.
Read the full article to learn how to Disable Automatic Hint Feature for the TTreeView.
Related:
- Display Custom TTreeView Item Hints
- Displaying XML (RSS Feed) Data in a TreeView
- TreeView with check boxes and radio buttons
Disable Automatic Hint Feature for the TTreeView originally appeared on About.com Delphi Programming on Thursday, March 4th, 2010 at 02:00:27.
Delphi tutorial video: Building REST applications that work with data and Google Spreadsheets
Delphi tutorial video: Extending functionality of a REST client with Yahoo and Google Maps
Understanding Unicode Support in Delphi
What does this mean? Will you have trouble migrating your "ansi" applications? How to create new Unicode Delphi application? What has changed with Char, String and PChar types?
Read the full article to learn about Unicode Support in Delphi
Related:
- Book Review: Delphi 2009 Handbook by Marco Cantu
- What Were the "Missing Tutorials" When You Started With Delphi?
- Top 10 Fun Reasons why you Should Stop Using Delphi, now!
Understanding Unicode Support in Delphi originally appeared on About.com Delphi Programming on Tuesday, March 2nd, 2010 at 08:08:51.



