News, Blogs, and Tips

YouTube Video of Myself Presenting Book and Seminar

Marco Cantu - Tue, 03/16/2010 - 18:39

While I was in Scotts Valley last week, David I recorded a video of myself to present my Delphi 2010 Handbook, the promotion the company is running for my book, and my Delphi Developer Days seminars. Now the video has been edited and posted on YouTube, as you can see below:

More info on how registered users of Delphi 2010 can download my book and the TMS Control Pack on http://edn.embarcadero.com/article/40485. You can buy the printed version of my book on Amazon. Info on the seminars organized with Cary Jensen at www.delphideveloperdays.com.


Categories: News, Blogs, and Tips

Fun With Testing DateUtils.pas #2

Nick Hodges - Tue, 03/16/2010 - 11:26

First of all, thanks for the help improving the CreateRandomDate function.  I confess that I didn’t spend enough time thinking on it, and I’ll also confess that you guys are way smarter than I am.  ;-)  I’ll post the “updated” version for your perusal in a separate post. 

In addition, you all were right – that code formatting sucks.   The plug-in I got for Live Writer was not very configurable.  I am now using John Kasters “YAPP” tool, and it all looks a lot better. 

Okay, back to the show…..

So to get going with unit testing DateUtils.pas, I naturally simply “plugged in” to our existing RTL unit test framework.  We have an existing RTL set of unit tests for running DUnit tests on the RTL.  I simply added the unit UnitTest.DateUtils.pas to the project, created the new class:

TDateUtilsTests = class(TTestCase) end;

and I was in business.  From there, it’s merely a matter of declaring published methods that run the DUnit tests.

So, I started right at the top with DateOf and TimeOf. So, what to test? Well, the most obvious thing: Does DateOf actually return the date portion of a given TDateTime?  Well, lets create a TDateTime with a random time, then, lets create a TDate with the same date but no time at all, and see if DateOf can do it’s magic?

procedure TDateUtilsTests.Test_DateOf; var TestDate: TDateTime; Expected: TDateTime; Result : TDateTime; begin TestDate := EncodeDateTime(1945, 12, 1, 1, 46, 13, 112); Expected := EncodeDate(1945, 12, 1); Result := DateOf(TestDate); CheckTrue(SameDate(Result, Expected), 'Test date and Expected date were not the same.' + ' DateOf function failed. Test #1'); end;

So this is a pretty straightforward test – you create two dates, and see if they are the same after the call to DateOf.  Simple.

What if you, say, increment the time part by one millisecond.  Come on, that can’t hurt anything right?  Better make sure:

// This test will fail if it gets run at 23:59.999 at night. // I'm willing to gamble that this will never happen. TestDate := Now; Expected := IncMillisecond(TestDate); Result := DateOf(TestDate); CheckTrue(SameDate(Result, Expected), 'Test date and Expected date were not the same.' + ' DateOf function failed. Test #2');

Okay, those are some “positive test cases”.  (I have a bunch more different ones along these lines….)  What about testing the negative case?  That is, test where we know that the two dates should be different after the call, and we test to make sure that they are, indeed different.

TestDate := Now; Expected := DateOf(IncDay(TestDate)); Result := DateOf(TestDate); CheckFalse(SameDate(Result, Expected), 'Test date and Expected date should have' + ' been different but they weren''t. Test #2');

I have a similar set of tests for TimeOf.  These are pretty basic, but that is where you start, right?  With the basics?  From there, I wrote tests that change only the milliseconds, the seconds, the minutes and the hours.  All should never allow the DateOf function to return anything other than the date.  For TimeOf, I do the same – change the year, month, and date and make sure the time is the same.  Then I purposefully change the time and make sure that the function actually does change the time. 

Now, some of you are going to chastise me for using other DateUtils.pas functions to write tests.  Two schools of thought on that.  One says that you should never rely on anything outside of the actually call being tested.  Another says to use those library functions because they’ll get tested all the more when used in other tests. I’m going to be following the latter philosophy, and as well see in a later post, this way of doing things actually will reveal a pretty significant bug in a routine that was used to test another routine.

Categories: News, Blogs, and Tips

IDE Fix Pack 3.0 released

Andy’s Blog and Tools - Tue, 03/16/2010 - 10:30

Yesterday I released a new version of the IDE Fix Pack. The new version 3.0 adds some object inspector patches and removes one patch that caused problems with the compiler and debugger hint windows.

Changelog from 2.9 to 3.0 (2010-03-15):

  • Added fix for: QC #80822: ObjectInspecor: Properties are duplicated after scrolling
  • Added fix for: QC #80776: ObjectInspector shows “EditControl” instead of the real content
  • Added fix for: QC #79776: Clicking on object Inspector rejects focus
  • Added fix for: QC #29732: Class Completion adds published section
  • Added fix for: Step-Out doesn’t recognize the return address at ESP (2010 only)
  • Removed broken fix for QC #47242: Possible AV when shutting down the IDE
Categories: News, Blogs, and Tips

Minesweeper Game - Delphi Version with Source Code

About.com Delphi Programming - Mon, 03/15/2010 - 19:00

in Delphi Games ::
Minesweeper is a single-player computer game. The object of the game is to clear a minefield without detonating a mine. The most well-known version comes bundled with Windows.

Go to the full article to Download Minesweeper Game - Delphi Version with Source Code

Related:

Minesweeper Game - Delphi Version with Source Code originally appeared on About.com Delphi Programming on Tuesday, March 16th, 2010 at 02:00:56.

Permalink | Comment | Email this

Categories: News, Blogs, and Tips

Snap Mouse To The Default Button in a Dialog Box in Delphi Applications

About.com Delphi Programming - Sun, 03/14/2010 - 21:07
in Mouse Programming :: Unfortunately for your Delphi application users, the "move pointer to the default button in dialog boxes" feature is not handled by your Delphi application. The mouse pointer will not jump for Delphi dialog boxes like InputBox, MessageBox, ShowMessage or any custom made modal form / window. Here's a quick fix.

Read the full article to learn how to Correct the Snap-To Feature: Move Mouse Over the Default Dialog/Modal Window Button.

Related:

Snap Mouse To The Default Button in a Dialog Box in Delphi Applications originally appeared on About.com Delphi Programming on Monday, March 15th, 2010 at 04:07:56.

Permalink | Comment | Email this

Categories: News, Blogs, and Tips

Delphi 2010 Handbook Discount on Amazon

Marco Cantu - Thu, 03/11/2010 - 17:54

Just wanted to mention the book sell for 20% on Amazon.com, right now. It is listed at 34.25 USD rather than the full price of 43.50 USD. The link for buying is http://www.amazon.com/Delphi-2010-Handbook-Features-upgrading/dp/1450597262/

PS. Did not blog through this entire week as I was traveling in California, was in silicon valley and spend some time in Scotts Valley with members of the Delphi  R&D team (hey, thanks for the pizza!) and other Embarcadero employees. A special thank to David I who found some stuff for my daughter and to Lino who offered me a great dinner. I'm at SFO right now, heading home. I got to see some cool technology (also from Microsoft), but under NDA. 


Categories: News, Blogs, and Tips

An Error at Run-Time due to the Database Connection Left Open at Design-Time

About.com Delphi Programming - Wed, 03/10/2010 - 20:00

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:

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.

Permalink | Comment | Email this

Categories: News, Blogs, and Tips

Fun With Testing DateUtils.pas #1

Nick Hodges - Wed, 03/10/2010 - 10:22

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.

Categories: News, Blogs, and Tips

Random Thoughts on the Passing Scene #149

Nick Hodges - Tue, 03/09/2010 - 14:42
  • 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.
Categories: News, Blogs, and Tips

Two more RAD Studio/Delphi/C++Builder/Delphi Prism webinars this month

Sip from the Firehose - David I - Tue, 03/09/2010 - 09:00

March has been a big month for development webinars on EDN.  We have two more webinars to go before we are finished: 

The other webinars that have recently taken place include:

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.

Categories: News, Blogs, and Tips

Selecting Delphi's TListView Item When the Item's Checkbox is Checked

About.com Delphi Programming - Mon, 03/08/2010 - 23:29
in TListView Tips and Tricks :: When the Checkboxes property is True, ListView includes a check box next to the items in the list. To get the "checked" state for an item in the list view, read the Checked boolean property.

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:

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.

Permalink | Comment | Email this

Categories: News, Blogs, and Tips

Adding Custom Properties to Delphi Forms; Overriding the Create Constructor

About.com Delphi Programming - Sun, 03/07/2010 - 19:00

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.

Permalink | Comment | Email this

Categories: News, Blogs, and Tips

Delphi 2010 Handbook on Amazon, Developer Network

Marco Cantu - Sat, 03/06/2010 - 00:37

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.


Categories: News, Blogs, and Tips

Fun Phone Calls with Delphi Prism

Nick Hodges - Fri, 03/05/2010 - 16:05

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 doLINQ, 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. 

Categories: News, Blogs, and Tips
Syndicate content