Did you know if you add an object to a collection, and the object contains a RELEASE method, it will automatically be removed from the collection when the object is released?

Check out this example code:

oCollection = CREATEOBJECT("MyCollection")
FOR i = 1 TO 10
   IF MOD(i,3) == 0
      ?"No Release"
      o = CREATEOBJECT("ObjNoRelease")
      o = CREATEOBJECT("ObjWithRelease")
      ?"With Release()"
?"Collection Count: " + ;
lnCount = oCollection.Count
FOR i = lnCount TO 1 STEP -1
   oObj = oCollection.Item(i)
      ?"Collection Count: " + ;
?"Collection Count: " + ;
DEFINE CLASS ObjWithRelease As Session
   PROCEDURE Release
DEFINE CLASS ObjNoRelease As Session

DEFINE CLASS MyCollection As Collection

Objects with a RELEASE method magically disappear from the collection when they are released. This makes for an easy way to keep track of opened threads when using Christof’s DMULT.DLL for multithreading. All I have to do is make sure my callback objects have a Release method, and periodically check the “ThreadManager” collection Count property to see how many threads may still be running.

Shameless Self-Promotion

Next Thursday (June 21), I’ll be speaking at the Atlanta FoxPro Users Group meeting. I’ll be presenting the “Easy Multithreading with Visual FoxPro” session I did at Southwest Fox 2011.

Since I’ve done the session at Southwest Fox,  Detroit Area Fox Users Group and the Chicago FoxPro Users and Developers Group, I reckon it’s time to “retire” the session from “the road” after Atlanta.

So, in the next couple of weeks I’ll be posting the slides, code and whitepaper for the session.

If you haven’t seen the session, here’s a quick little “promotional” video for it (with tongue planted firmly in cheek).



Christof Is A Freaking Genius

A cool part of the Southwest Fox conference last year was a couple of bonus sessions called Show Us Your App, where several FoxPro developers were given an opportunity to spend 5 to 10 minutes showing off things they’ve worked on.

I showed one of my apps, and focused primarily on how easy it was to add multi-threading capabilities to the app.

Easy, because Christof Wollenhaupt made it easy.

He answered a question in FoxPro Advisor (back when it was an actual magazine) about multi-threading in Visual FoxPro. In his answer, he talked about a DLL he had written which basically allows you to run code in a separate thread. That’s an understatement – one day I’ll write an actual article about my experience and expand on it a bit.

The app I showed uses the IE Web Browser control as it’s primary UI. There are a ton of hyperlinks on certain pages. You click a link and it fires off an HTTP request to collect information and save the collected info into a table.

Since I just love to control how the user uses the app, I displayed a modal window while this request was taking place.

After reading Christof’s piece in Advisor, I decided to use his DLL and make the requests multi-threaded. Now when you click a link, the HTTP request is fired (on a separate thread) and control is immediately returned back to the app. You can click another link while the first one is processing. And another, and another, and another. S-w-e-e-t!

Anyway, during my Show Us Your App bit I mentioned for anyone in the audience that didn’t already know: “Christof is a freaking GENIUS!” (I suspect everyone in the room already knew that). I joked that I was planning to ask my boss to rename the app “Christof Is A Freaking Genius” in honor of the positive effect his work had on my work.

Christof returns to Southwest Fox this year with a pre-conference session titled TLAs put into Practice: Object Oriented Principles in VFP, and a regular conference session titled How the Fox is Different.

He has presented at several Southwest Fox conferences. Last year, he presented Excelporting and Using .NET in FoxPro Applications. Back in 2007, he presented the still-talked-about On the Dark Side of FoxPro.

He is also the creator of Guineu (an alternative runtime library for Microsoft Visual FoxPro 9.0 that runs on any Microsoft .NET compatible platform).

Have a look at his website whitepapersdownloads, and Knowlbits. If you’ve ever wanted to learn more about Visual FoxPro (especially the internals of FoxPro), and you’ve read anything Christof has written, I’m sure you will agree that Christof is a freaking Genius.

He’s also a very friendly and helpful person. Definitely a highlight of attending last year’s conference was the opportunity I had to meet and talk with him.

Poor guy. I followed him around the conference like a puppy dog, making statements and asking questions that I’m sure made me sound like the hack programmer I am. He was friendly, patient, and extremely helpful. I’ll always be grateful for the time I got to spend with him.

I’m looking forward to seeing him again this October.