Hey, I know you all must be super disappointed I didn't have any Code of the Day today.  My apologies.

Comments

  1. if Assigned(FLock) then
    FreeAndNil(FLock);
    :)

    ReplyDelete
  2. Wow!  No new uglies? How can that be? Oh, wait, you haven't opened any code today?  ;)

    ReplyDelete
  3. Nándor Kiss I sometimes write such code for debugging purpose, to be able to put a breakpoint on FreeAndNil in order to verify is the variable has been assigned in a particular test case. This code should be simplifyed later but sometimes it is forgotten.

    ReplyDelete
  4. Yesterday I ran into this kind of code:
    class procedure TfrmChild.DoSomething;
    begin
      frmChild.SomeProperty := 10;
      frmChild.ThisAndThat;
    end;

    ReplyDelete
  5. var
      tmpVar: Variant;
    ...
          tmpVar := SomeFunctionReturningVariant(...);
          if not(VarIsEmpty(tmpVar) or VarIsNull(tmpVar)) then
            SomeString := VarToStr(tmpVar)
          else
            SomeString := '';

    repeated more than 20 times with different arguments to function and different string variables

    ReplyDelete

Post a Comment