New topic: 

NilObject with FolderItems in use

<http://forums.realsoftware.com/viewtopic.php?t=29730>

       Page 1 of 1
   [ 7 posts ]                 Previous topic | Next topic         Author  
Message       applesource           Post subject: NilObject with FolderItems in 
usePosted: Tue Aug 25, 2009 1:10 pm                        
Joined: Thu Aug 06, 2009 2:25 pm
Posts: 90
Location: Oregon              I'm having an interesting issue where people are 
reporting NilObjectExceptions. I've trapped this down and realized it's in an 
autosave timer. What I need to do is figure out if a file is already being 
saved/read and if so, NOT to fire the autosave timer's code.

What's the proper method of checking if a folderitem is open/in use before 
attempting to write to it again?

Thank you!     
_________________
AppleSource Software
http://www.applesource.biz  
                            Top                timhare           Post subject: 
Re: NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:21 pm           
             
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6177
Location: Portland, OR  USA              Probaby easiest to check for nil in 
your autosave code and bail out if you can't open the file because it's already 
in use.   
                            Top               applesource           Post 
subject: Re: NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:21 pm  
                      
Joined: Thu Aug 06, 2009 2:25 pm
Posts: 90
Location: Oregon              In addition, this only occurs under Mac OS X 
10.4, under 10.5 there are no issues at all with the auto save timer. Not sure 
why this is, or what could cause the problem. But ultimately I just need to be 
able to check to see if a folderitem is already open/in use before I attempt to 
save the data to it.

Any ideas?     
_________________
AppleSource Software
http://www.applesource.biz  
                            Top                applesource           Post 
subject: Re: NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:23 pm  
                      
Joined: Thu Aug 06, 2009 2:25 pm
Posts: 90
Location: Oregon              Tim,

I do check for nil before I do anything with a folderitem. But this issue still 
occurs on 10.4.

What's the best way to check for nil besides just doing an "if not (f is nil) 
and f.exists then" before opening the file? Should I put an exception to trap a 
Nil error at the bottom of the routine?

Seems weird there isn't just a folderitem.inuse flag, or something similar.     
_________________
AppleSource Software
http://www.applesource.biz  
                            Top                ZULU           Post subject: Re: 
NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:37 pm               
         
Joined: Mon Jul 31, 2006 1:44 am
Posts: 999              I think you need to clarify some ...
A folderitem can't be open ....

If you mean you get an NilObjectException when trying to write the file, then 
you not checking the TextOutputStream, if it is that you use ( Can't guess )

So little more info and perhaps your code ...     
_________________
------------------------------------  
                            Top               timhare           Post subject: 
Re: NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:40 pm           
             
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6177
Location: Portland, OR  USA              I suspect you're getting the 
folderitem ok, but it's failing when it tries to return an InputStream (either 
Text or Binary, depending on how you're accessing the file).
Code:dim f as folderitem
dim txt as TextInputStream
f = GetFolderItem(...)
if f<>nil and f.Exists then
  txt = f.OpenAsTextFile  // this returns nil if the file is in use
  if txt = nil then return  // so bail out
  ...
  

HTH,
Tim   
                            Top               applesource           Post 
subject: Re: NilObject with FolderItems in usePosted: Tue Aug 25, 2009 1:42 pm  
                      
Joined: Thu Aug 06, 2009 2:25 pm
Posts: 90
Location: Oregon              I'm using TextInputStream/OutputStream.

I will try checking for nil on the streams and see if that reduces or 
eliminates the errors being received. Thanks for everyone's help.     
_________________
AppleSource Software
http://www.applesource.biz  
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 7 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to