Skip to content

Monthly Archives: April 2008

Solution to “Searching for Bobby Fisher”

In Roddy's own words:
"I was using the "Find" method on an unsorted TStringlist... which you're not supposed to do. Sometimes it works (my initial test case had the items in my list already sorted, just by coincidence), but usually it doesn't..."
So, Roddy had two options:

{...}

Names.LoadFromFile('names.txt');

Names.Sorted := True;

{...}

...or...

//Instead of using Names.find, do the following:

Result := [...]

Searching for Bobby Fisher

Special thanks to puzzle regular Roddy Pratt for suggesting the idea for this week's puzzle.
Roddy (*Names may have been changed to protect the innocent) had code similar to the following:

function FindBobbyFisher: Integer;

var

  Names: TStringList;

  I: Integer;

begin

  Names := TStringList.Create;

  Names.LoadFromFile('names.txt');

  if not Names.Find('Bobby Fisher', I) then

    Result := -1

  else

    Result := I;

  [...]

Answer to “Include”

The problem here was with the {$INCLUDE} directives.  The following line compiles in the IDE, but not from the command line (or from a build tool that uses the command line compiler):
{$INCLUDE ../includes/dotnet.inc}
The fix?  Use backslashes in the file path, not forward slashes:
{$INCLUDE ..\includes\dotnet.inc}

Include

Kyle put the following code in his file:

{$IFDEF CLR}

  {$INCLUDE ../includes/dotnet.inc}

{$ELSE}

  {$INCLUDE ../includes/win32.inc}

{$ENDIF}

During testing, everything worked as expected, but after checking in all the files, he got an email from the build machine telling him he broke the build.
What did he do wrong?