Skip to content

Monthly Archives: January 2008

Bluff the Programmer

I enjoy listening to National Public Radio's Wait Wait Don't Tell Me" on saturday mornings. "Wait Wait" is a show in which listeners call in and are quizzed (in very humorous fashion) by normally respectable newscasters and radio personalities, and if they get their quizzes right, the big prize is Carl Kassel's voice on [...]

Solution to “Short and… what?”

In Windows, resource names have to be in all caps. 'Bitmap1' is not a legal resource name, but 'BITMAP1' is.
However, that's not the complete answer, because this code will work - the API for dealing with resource will take the uncapitalized names and work with them as if they were capitalized. But if [...]

Short and… what?

Last week's puzzle was lengthy and took some thinking to figure out. This week's is simple, and if you know it, you'll know it right away.
If you saw the following code, and were told it wasn't working right, what would you first suspect the problem is?

Image1.Picture.Bitmap.LoadFromResourceName(HINSTANCE, 'Bitmap1');

(Edited about 12 hours after posting for [...]

Solution to “I have to watch my soaps”

This one was actually based on code I wrote, and a bug I created. It wasn't in Delphi though, but the logic error I created was interesting enough to make a note and turn it into a puzzle. When I translated the buggy code into Delphi, it behaved exactly the way I expected. [...]

I have to watch my soaps

Pedro is a graduate student at the university, and has been asked to help create a program to run the university television station. Pedro's job is to write Delphi code to make data in the database useable for both a desktop application and a web application.
Today, Pedro has been tasked with writing a routine [...]

Solution to Passing Grades

Peter has missed the double meaning of the NOT operator. He wants to see all of the students that do not have a grade over 60, so he uses this line to see if the grade is where he wants it:

if not AllStudents[I].CalculateGrade> 60 then

  FailingList.Add(AllStudents[I]);

What Peter doesn't realize is that in this [...]

Passing Grades

Peter, a school teacher, is writing an application in Delphi 7 to help him track the grades of his students. Today he is writing code that will give him a list of all the students in his class that are not passing. Peter defines a passing grade as a grade higher than 60%. [...]

Solution to A Little Housekeeping

Sarah's mistake was in the way she moved through the records in her table. She started with the basic pattern of iteration through a table:

Table1.First;

while not Table1.EOF do

begin

  {process record here}

  Table1.Next;

end;

Then she added code to check the record and delete it if its CreationDate was before January 1, 1998. The problem [...]