Can anyone think of a reason why someone would write:

Can anyone think of a reason why someone would write:

   if (aRecordSet <> nil) and ((aRecordSet.State and cardinal(osStateOpen)) = Cardinal(osStateOpen)) then
    begin
      aRecordSet.Close;
    end;

instead of just:

   if (aRecordSet <> nil) and aRecordSet.State = adStateOpen?
    begin
      aRecordSet.Close;
    end;

Comments

  1. I should note that osStateOpen is an enumerated Type.

    ReplyDelete
  2. They're not equivalent.  The first is closer to:

    if (aRecordSet <> nil) and (adStateOpen in aRecordSet.State) then

    Maybe they were new to Delphi and weren't used to dealing with sets?

    ReplyDelete
  3. Thanks, Craig -- it's probably something like that.

    ReplyDelete
  4. My first thought was Delphi 3 era compiler glitches.

    ReplyDelete
  5. Warren Postma  I was looking at some "if Count>0 then for i:=0 to Count" blocks the other day and thinking happily that at least that bug is gone now.

    ReplyDelete
  6. Is State a bit set ?
    Also: osStateOpen or adStateOpen?

    ReplyDelete
  7. Maybe somebody discovered bit wise operations and as sometimes when you discover something new, you try to apply it "a little bit" to much ...

    ReplyDelete

Post a Comment