[futurebasic] Re: [FB] When a Toolbox function returns NULL

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Tue, 9 Aug 2011 16:46:50 +1200
Ken Shmidheiser wrote:

> According to the Apple docs, MDItemCopyAttribute can return a NULL if 
> an attribute doesn't exist. How do you deal with a NULL in FB. The 
> following function returns a file's creation date, but it is possible 
> for a file not to have a creation date and the subsequent NULL will 
> crash the code. This is trivial enough to handle in C, but is there a 
> practical FB solution?

NULL is a macro in C, equal to (void*)0. In FB, you can simply compare against 0, or you can daringly introduce the symbol 'NULL'.

system pointer  NULL
if ( somePointerVar == NULL ) then ...


> Also, I should mention that my earlier code example should have used 
> @"kMDItemFSCreationDate" and @"kMDItemFSContentChangeDate".

Please use the predefined constants declared in Tlbx MDItem.incl (kMDItemFSCreationDate, kMDItemFSContentChangeDate...) instead of string literals.

Robert P.