Amazon.com Widgets Tech Stuff

Accessing Private Stuff with Interfaces

By Nick at June 27, 2011 08:38
Filed Under: Delphi, Tech Stuff

I have to admit that the following code surprised me.  I guess it makes sense, but I wouldn’t have guessed that you can expose private functionality via an interface like this.  Interesting. 

program DoPrivateStuff;

{$APPTYPE CONSOLE}

uses
  SysUtils;


type

  ITestInterface = interface
    procedure DoThisPrivateThing;
    procedure DoThisPublicThing;
  end;

  TTestClass = class(TInterfacedObject, ITestInterface)
  private
    procedure DoThisPrivateThing;
  public
    procedure DoThisPublicThing;
  end;

{ TTestClass }

procedure TTestClass.DoThisPublicThing;
begin
  Writeln('Doing a public thing');
end;

procedure TTestClass.DoThisPrivateThing;
begin
  WriteLn('Doing a private thing');
end;

var
   Test: ITestInterface;

begin
  try
    Test := TTestClass.Create;
    Test.DoThisPrivateThing;
    Test.DoThisPublicThing;
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Flotsam and Jetsam #37

By Nick at June 22, 2011 03:06
Filed Under: Delphi, Flotsam and Jetsam, Tech Stuff
  • Marco Cantu has published his new book on Delphi XE.  I’ve been given an advanced copy (thanks, Marco!) and as you’d expect, it is excellent.  We are going to buy some copies here at Gateway Ticketing for use in our transition to Delphi XE.  As with everything Marco does, it is highly recommended
  • There a new Facebook group for Delphi Developers that seems to have a lot of activity.  You might consider joining.  It would be good for Delphi people to congregate in a single place on Facebook to share links and information, and this might be the place. 
  • And speaking of Facebook, you can now ’Like’ Embarcadero’s AppWave on Facebook.  I’m still not clear on exactly where all this AppWave thing is going, but it does look interesting.  I wonder what affect the “appstore” in Windows 8 will have on it.  I guess one advantage that AppWave has is that it is here right now, and Windows 8 is still pretty much vaporware at this point.
  • I went to see the Green Lantern this past weekend.  Highly recommended – I have no idea what all the bad reviews were about.  Great comic book movie.  (Those reviewers know that the Green Lantern is a comic book movie, right?)  The tech angle here is that it was the first time that I had seen a movie in 3D.  My take?  I never want to see a movie – any move, I don’t care if it’s a “blockbuster” or not – in 2D again. It was a terrific experience. This is a great feature that will definitely get me in the theater more. I have been going to the theatre less and less because of Netflix, but if I can see the upcoming Harry Potter movie in 3D, I will.  Looking forward to it being the normal experience on TV.
  • David I has been at Borland, Inprise, Borland, CodeGear, and now Embarcadero for 26 years.  He’s seen it all.  Congratulations to a titan of the industry – and a great guy.  I’ve known David for many years – since I met him at a PC User group at the Naval Postgraduate School in around 1994 – and it’s been an honor to be his friend.
  • I love a good story like this:  Throw Away that Hotel Soap.  There is staggering waste in our economy (anyone buying cases of plastic bottles of water – I’m looking at you…) and this is the kind of thing I love to see.

A Big Thank You

By Nick at April 15, 2011 04:59
Filed Under: Delphi, Software Development, Tech Stuff

I’d like to pass on a big thank you to Marco Cantu, Cary Jensen, and Cary’s lovely wife Loy Anderson for their wonderful hospitality while I was at Delphi Developer Days in Baltimore earlier this week.  It was an honor to be asked to be a guest speaker at the event, and I hope that my talk on unit testing with Delphi was worthy of the conference.  Cary also graciously gave me a signed copy of his excellent new book, Delphi in Depth: ClientDataSets

I should add that the conference was very valuable.  Cary and Marco do a great job and there were a lot of good examples and code, as well as a very nice manual with tons of great articles in it.  I heartily recommend attending next year if you are so inclined.

Flotsam and Jetsam #22

By Nick at January 28, 2011 04:35
Filed Under: Flotsam and Jetsam, Delphi, Tech Stuff
  • SDTimes has an interesting article about a “Delphi Starter Edition”.  It appears that the Starter version will limit the revenue of a user to $1000 in overall revenue, as well as limiting all database access.  They are going to be priced at $199.  It also seems like there can only be five of them in any given organization.  Folks in the community are discovering that the Starter Edition will be available February 1.  And now Tim Del Chiaro has confirmed it in his blog.
  • We recently changed the name of our “Inside Sales Representatives” to be “Account Relationship Managers”.   This lead to the following statement in our weekly Manager’s Meeting: “Well, that’s really in the hands of the ARMs”.  Heh Heh.
  • I want a Rovio.
  • I just realized that I have a Windows key on my keyboard and that I don’t think I’ve ever used it once. Now, I know that the key has been there for a long time, but I just now realized that I simply never press it. Maybe I should be.  Do you guys actually ever hit the Windows key?
  • Today marks the the 25th year after the Challenger explosion, and I heard them on the Radio talking about it, saying “Do you remember where you were"?”   I remember it as clear as day. I was standing in the front office at Pasadena High School, where I was a Latin and English teacher.  Our principal, Tom Hancock, came out of his office with an ashen look on his face and said “Challenger just exploded”.  It hit our area particularly hard, as Pasadena is a suburb of Houston, with a major NASA facility nearby (The famous “Houston Control”), and the astronauts had lived and trained in the area.  That moment is a very start memory for me.

Update on THTMLWriter

By Nick at January 06, 2011 03:56
Filed Under: Software Development, Delphi, Tech Stuff, Unit Testing

I’ve made a fairly significant change to THTMLWriter.  (Even if you aren’t a use of THTMLWriter, please keep reading, there’s a valuable lesson at the end.)

What Did I Do?

I created an interface – IHTMLWriter – which simply lists the public interface of the class – and then had THTMLWriter implement that interface.  Not a big deal.  The big deal is that now the Fluent Interface is done with the IHTMLWriter interface instead of the class itself.  This shouldn’t be a big deal if you are using the class – you merely need to change the variable declaration to IHTMLWriter, and remove any code that destroys/frees the class you may have created. 

Why did I do this?  Well, I have to confess that it was partly because I could.  But I also think that in general, interfaces are better to deal with, particularly with the fluent interface.  I’ve noticed that interfaces appear to be the typical way that such things are implemented.  In addition, an interface limits the scope available to the consumer of a class.  If  you can only use a class via the interface, I as the developer can decouple the implementation from the interface – something that is always good. Plus, if one of you fine people feels like there is a better way to crank out HTML, now you can do it, too, using the same interface. 

The Valuable Lesson

Here’s the part that you all need to read:  I was able to make this rather large change with a lot of confidence because I had a pretty extensive set of unit tests to back me up. 

The initial change – creating the IHTMLWriter interface and changing the class to implement and use it – broke everything.  No test would pass, and the test program did nothing but raise access violations.  So, of course, I went to work and fixed things up.  I had to change a little architecture, alter the way a few things were done, and generally fix things up. 

All of my debugging was done on the test project.  It provided a perfect, simple reproduction of the bugs.  The unit tests enabled me to easily step through simple examples and find the places where the bugs were and where things weren’t working right.  And eventually the tests all “turned green”. 

GoingGreen

And let me tell you, turning green is sweet!  First, it feels really good. I kept running the tests and watching that little green bar slide across because it felt great.  Why did it feel great?  Because I knew that my changes were complete and  because I had confidence that things were all working as they were supposed to.   The only way that was possible was because of the existence of the unit tests.  Without them, I’d never really ever be sure that things were back to normal and working.

Time Well Spent

So the unit tests allowed me to forge ahead with confidence, provided me with a useful and powerful vehicle for testing and debugging my changes, ensured that I would know when I was done, and enabled me to prove that things were working as they should – all while making a fairly substantial change to a fairly complex code library. 

And some people say they don’t have the time to write unit tests.  I say you don’t have the time not to.

Using Your BitTorrent Powers for Good, not Evil

By Nick at December 27, 2010 12:10
Filed Under: Tech Stuff

I’m a big fan of the BitTorrent Protocol.  It’s an amazingly simple yet clever protocol for easily and efficiently moving bits around on the internet.  By grabbing small chunks of a given file from multiple peer computers anywhere in the world, it can quickly and efficiently move files from one place to another. 

Sadly, BitTorrent has a bad reputation, as it is commonly used to move pirated software, music, movies, and TV shows around in violation of any number of copyright laws.  But the fact that it is used for nefarious purposes doesn’t make BitTorrent itself evil or illegal, anymore than cars are illegal for being used as bank robbery getaway vehicles.  It’s a shame that many companies and other organizations feel that they can’t avail themselves of BitTorrent because of its bad reputation.

In fact, there are plenty of legitimate uses for BitTorrent.  Many companies do use it to distribute their software.  For instance, Ubuntu provides torrents for their Linux distributions.  It’s a nice way to make large files available to customers fast and free – there’s no bandwidth limit or any fee associated with BitTorrent.  But be advised of one thing – once a torrent is out in the wild, there is no getting it back. It is totally roaming free out on the Interwebs.

Below is a screenshot of my µTorrent client, showing the torrents that I’m serving up from a server at my house.  Those Ubuntu files are quite popular, and because there are so many “seeders” (that is, other people making the file available for downloading), I was able  to download many of those files at rates over 2MB per second meaning I was downloading 650MB files in a matter of minutes.

Torrent

In addition to the Ubuntu files, I also went to ClearBits.net and downloaded a number of legal, free-and-clear torrents. I leave my client running 24 hours a day, and gladly give up some of my upstream bandwidth to support the good folks at Ubuntu and the furthering of the distribution of fine literature via completely legal torrents.  I like to think of it as a small contribution back to the community and doing my part to contribute to the legal side of BitTorrent.

So if you haven’t checked out BitTorrent, give it a look.  There are plenty of legitimate uses for it out there, and there’s no reason you can’t be using it  to distribute your software -- and maybe even providing a bit of bandwidth to the world. 

Announcing THTMLWriter

By Nick at November 22, 2010 00:44
Filed Under: Delphi, Software Development, Tech Stuff

I have started an open source project on GoogleCode called THTMLWriter.

THTMLWriter is a Delphi-based class library that enables you to create HTML code and HTML documents. It uses the fluent interface to make creating HTML text easy and natural.  You can create HTML Documents or HTML “chunks” by  using any tag as a base.

THTMLWriter is all class based.  I started out trying to do some fancy things with interfaces, but it just got too complicated, and so I opted to go with the “simplest thing that will work” option, and now you can write code that looks like this:

 

Temp := THTMLWriter.CreateDocument;
     TempHTML := Temp
                  .OpenHead
                    .AddAttribute('dweezle')
                    .AddText('farble')
                  .CloseTag
                  .OpenBody.AddAttribute('ding')
                      .OpenSpan
                        .AddAttribute('this', 'that')
                        .AddStyle('font: italic')
                        .OpenDiv
                          .AddAttribute('floo')
                          .AddText('Blah')
                        .CloseTag
                      .CloseTag
                      .AddText('Hoorah')
                      .AddBoldText(' Shadooby')
                      .OpenBold
                        .AddText('Goombah')
                      .CloseTag
                  .CloseTag
              .AsHTML;

 

The project more or less produces XHTML code at the 4.01 level – I’ve tried to be XHTML-compatible, but I confess I haven’t been fanatical about it.  That is one of the things I want to in the future.  In addition, I want to update the project to support HTML5.  I’m still thinking about how to do that.

The project is pretty complete – you should be able to construct most HTML constructs.  I’ve provided a lot of overrides and default parameters for many of the “normal” attributes on a given tag.   I’ll continue to update the project with improvements and refinements.  I’ve used HTML & XHTML Pocket Reference from O’Reilly as my guide. I haven’t quite implemented everything, but it’s definitely at the point the that it is ready for you fine  people.

The project includes a full set of DUnit tests to give you confidence that the code actually does what it is supposed to. 

I have added a lot of XMLDoc comments to the code, but it’s far from complete. I’ve used the Documentation Insight plugin from DevJET software – the guys who do the Delphi Spring Framework.  (I can’t recommend this plugin enough – an outstanding contribution to the Delphi community, above and beyond the amazing Delphi Spring Framework.)

You can get the code from Google code using Mercurial.  We are planning on migrating our codebase here at Gateway Ticketing to Mercurial after the first of the year, and this project was my learning curve for using Mercurial.  Now that I’ve been using Mercurial – a distributed source control system – I wonder how we as developers ever managed to use anything but a DVCS.  It is that good and that powerful.  I heartily recommend looking at migrating to a DVCS.  It’s so much more flexible and more powerful than a server based solution such as Subversion

I’d be very happy to add anyone to the project who is interested in contributing.  I’ll also be happy to integrate submitted patches as well.  This have been a fun project to keep my toe in the water of coding – being a manager now means I don’t get to code as much as I want --but living alone in Pennsylvania while my amazing wife moves our house out here has given me a lot of free time to code.

Enjoy and let me know what you think.

Setting up Hudson to compile Delphi Projects

By Nick at November 05, 2010 12:37
Filed Under: Software Development, Tech Stuff

Just like you should be using Source Control (even if you are a one man operation), you should be doing continuous integration.  We currently use CruiseControl.net, but we are giving Hudson a look here at Gateway Ticketing, and it seems likely that we’ll end up switching and using it.  So naturally, I decided to play around a bit with Hudson. We used Hudson quite extensively at Embarcadero, but I had never really given it a whirl myself.

This is the Hudson Dude whose picture shows up in the Hudson interface. 

hudsondude

He’s quite dapper, no?

Hudson is Java-based, but don’t let that scare you.  You need not know a lick of Java to use it effectively.  It is very, very easy to download, install, and get up and running.  I found this blog post helpful in that regard.  I was up an running in minutes.

Hudson has a very nice browser interface for configuration.  It also has a very large and growing collection of community of plug-ins.  Hudson also makes it really easy to install plug-ins by providing support right in the interface.  Add them isn’t much more than selecting them in a list an clicking install.

Plugins are important, because you are going to need them in order to do a Delphi build.  The first one you’ll want to install is the MSBuild plug-in.  This will allow you to choose MSBuild as a build environment.

screen

All of the popular source control systems have plug-ins. I’ve been using Mercurial on my local machine, and so I chose that plug-in as well. 

I also discovered, after a series of trial and errors that the setenv plug-in is pretty much required as well.  As you may know, to do command line builds of Delphi projects, you need to set a number of environment variables. This is usually done via the rsvars.bat file.  Well, Hudson doesn’t know about that at all, and I didn’t have much luck running it as a batch file before doing the build.  Hudson seems to isolate the environment for each individual action.  The setenv plug-in lets you set global and local environment variables for Hudson.  Since I’ll be doing a lot of Delphi builds, I selected “Manage Hudson” and took the items from rsvars.bat and set them up as Global Properties:screen1

Doing that is critical, as that sets everything up so that Hudson can find the files needed by every Delphi project to define the build targets.  There are a couple of StackOverflow questions about this very topic that recommend passing a few parameters, but I found that if you set up setenv to incorporate what rsvars.bat does, you don’t need to pass any parameters on the MSBuild command line beyond the *.dproj or *.groupproj filename. 

In addition, you need to tell Hudson about MSBuild specifically – that’s easily done in the global configuration as well. Basically you give each installation a name and the full path to the MSBuild.exe for that .net version.  You might want to set up different MSBuild installations for  the .NET 2.0 and .NET 4.0 versions, for instance.

screen3

Once all that is set up, it’s really a matter of setting pretty self-explanatory properties of Hudson.

  1. Select “New Job”. 
  2. From here, I just chose “Build a free-style software project” to do a simple build of a Delphi project group.
  3. Give your job a name and click Ok.
  4. From there, you can pretty much figure things out.   I did the following.
    1. Pointed Hudson to the Mercurial repository I wanted it to pull from, including the branch I wanted.  The settings for Subversion and other SCM systems may have different settings.
    2. I chose to poll Mercurial for changes.  The “code” for setting that up is a bit tricky, but I found pressing the help button gave a pretty good rundown and some examples.  I just set it to poll every minute.  Not a big deal on my local machine, and it makes it easier to see how things are working while testing it out. screen4
    3. The final thing to do was to actually tell Hudson what to build.  That was easy – I have a project group called

      C:\Code\HTMLWriter\HTMLWriterGroup.groupproj
      ,

      and I simply added that as the MSBuild build file after telling Hudson which version of MSBuild to use.
    screen8

And that is pretty much it. From there, you can tell Hudson to build for you on demand, or you can just leave it to run, and it will build everytime it sees a change in your source.  Again, the “tricky” part was getting and using that setenv plug-in.  That simplified everything. 

UPDATE: Christer Fahlgren has also written a very nice blog post about running Hudson on Delphi projects.

Getting a Router in Another Room

By Nick at July 27, 2010 07:19
Filed Under: Tech Stuff

If you are like me, you have some form of high-speed internet coming into your house. You probably have Cable or DSL or something else, and then a “main” router where there the Internet comes from “out there” to “in here”.  You probably then have it served up with a wireless router.  Me?  I have Comcast cable piped into a NETGEAR WNR2000 Wireless-N Router. From there, I send the wires out to three computers in the room for my wife and kids.  I then use the wireless with my notebook around  Works pretty well.

But I have an office upstairs, and I wanted to put a server up there as well as a notebook on a desk for my use.  That’s two computers.  Now the notebook has a wireless care built in, but the server doesn’t, and I loathed the idea of putting a wireless card in a desktop.  I could run a wire up through the house, but what a pain in the butt.  So I needed to figure out how to get my wireless signal up to a router in my office.

I went to Best Buy and I got a Linksys Bridge.  It was a bit tricky to set up, but I did, and it worked pretty well.  It was somewhat intermittent, but I was able to have  switch up in my office with connectivity to any number of machines. 

But then, out of nowhere, the thing stopped working.  It just bricked itself.  No lights, no power, no nothing. Great.  So, off to Best Buy again, with a determination not buy that Linksys Bridge again.  So the nice sales gal there pointed me to a NetGear Gaming router that is basically a wireless bridge.  I guess that these things are very popular for gaming consoles so they market them mostly to gamers.  So I’m slowly walking out, and this other guy comes up to me and says “That will work for what you want, but I can show you something that is faster and more reliable”. 

Well, I don’t know about you, but I am into faster and more reliable, so I followed him, and he showed me this:

I was a bit hesitant at first, as it seemed a bit strange to pump my connection through my household power lines and the box explicitly calls it an “XBox 360” kit (that gaming thing again), but the guy said it works perfectly for a regular network and that he’d personally take my return if it didn’t work exactly like I wanted.

Well, as far as I can tell, he’ll never see me again. This thing worked like a charm. It was pathetically easy to install – network cable out of my router, into device, which I plugged into the wall.  Then, up in the office, I plug in the other one, with a network cable out of it into my switch.  Simple, clean, and easy.  It worked immediately, and the total setup time (hardware only, no software to configure) was literally five minutes. 

So far, it’s working great.  I now want to find out if I can buy one of these things and use it in yet another room.  That would be even cooler, as we have a renter who’d really appreciate that.

All in all, a purchase that I’m really happy with.

My Book

A Pithy Quote for You

"Good judgement is the result of experience ... Experience is the result of bad judgement."    –  Fred Brooks

Amazon Gift Cards

General Disclaimer

The views I express here are entirely my own and not necessarily those of any other rational person or organization.  However, I strongly recommend that you agree with pretty much everything I say because, well, I'm right.  Most of the time. Except when I'm not, in which case, you shouldn't agree with me.