Checking for null date

Steve Albin steve at steve-albin.com
Sun Mar 29 15:03:55 CDT 2009


On Sunday, March 29, 2009 sunshine at public.kherson.ua (Ruslan Zasukhin) wrote:
>----------------------
>Another TIP
>
>So you wrtie:
>
>  if VDateTime(cursor.Field(27)).Value <> nil then
>      Return  VDateTime(cursor.Field(27)).Value
>  else
>      Return nil
>  end
>
>
>I'd never write such code in any language,
>Because it is known that TYPE CAST operation is not easy.
>So why do it twice?

You are correct that casting twice is wasting time.  But, more importantly, the casting does not work as expected in this case.  I've just tried the above code and the if statement does not pick up the field as null. 

To be clear, given that field(27) is null:

 VDateTime(cursor.Field(27)).Value = nil     returns false
 
 VDateTime(cursor.Field(27)).IsNull          returns true
 
 
This makes sense to me now.  We are telling RB to expect a date but giving it a nil value.  RB will not make a correct date of it, but the end result will not be nil.
 
  
 
This is all moot anyway since casting is the wrong approach and now I've learned the correct approach.  


Thanks,
Steve


-- 
Steve Albin - Montclair, NJ
http://www.jazzdiscography.com/
http://www.steve-albin.com/


More information about the Valentina mailing list