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 := [...]
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;
[...]
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}
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?
Friday, February 22, 2008
This puzzle came about a couple weeks ago when I was in a church. I looked at the hymn board and discovered that there were so many "1"s on the board that they had run out, and someone had turned a "7" upside-down and covered the horizontal part with masking tape. I thought, [...]
Monday, February 18, 2008
You've been hired by a company that creates hymn boards - a plaque that goes on the wall of a church showing which songs are to be sung during a church service:
Your task is to create an algorithm to determine the minimum number of each digit card (the little cards with a single digit, 0-9, [...]
Friday, February 15, 2008
Steven pointed out that Ray's code did not gracefully handle the application closing. If the application closed while there were still transactions processing, the application would simply appear to hang, with its user interface frozen, until either all the transactions were processed, or the user killed the process.
The solution is to check Application.Terminated in [...]
Monday, February 11, 2008
Ray was a junior developer at a large, nameless bank. One of the applications his group maintained was one that settled certain transactions. Ray was tasked with seeing if he could make the application run any faster. He discovered that the major bottleneck was processing on a network server, and decided that [...]
Delphi Puzzles is taking the week off this week.
The site is being moved to a new server, and to make sure that we don't lose any comments in the process, there is no puzzle this week. It will be back in full force, better-than-ever, next week.
--Jacob
The valid code is option #1:
Memo1.Lines.Add(Format('1: %s' + ^M + '2: %s', [Edit1.Text, Edit2.Text]);
^M is a Delphi code construct that compiles, but I haven't found it documented anywhere. The ^M is character - analogue to #13#10 (or \n in c parlance). The + operators aren't even necessary. You can do 'string1'^M'string2' [...]