Note 37: You can write the code also with the classic if-then-else statement, rather then using the initial assignment to the Result:
if ItemIndex >= 0 then
Result := Items [ItemIndex]
else
Result := '';
I tend to prefer setting uninitialized stack values, including local variables and results, even when it is not strictly required, because failing to do so at times results in hard-to-track errors.
To make the note understandable, here is the actual code in the book. Which style do you prefer?
Result := '';
if ItemIndex >= 0 then
Result := Items [ItemIndex];
This blog post is part of my "113 Delphi 2007 Handbook Notes" blogging project, to promote my new Delphi book.