realbasic-nug
[Top] [All Lists]

FolderItem.Item Can Return Incorrect Results

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: FolderItem.Item Can Return Incorrect Results
From: "Stephen E. Hutson" <mail_lists@adpartnership.net>
Date: Sun, 28 Sep 2008 20:47:41 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Greetings,

I have found that if the user or another app changes a folder's contents after the built RB app launches, the first time the folder is accessed, the contents [folderitem.item(n)] are incorrectly reported, with nil folderitems for the removed files.

This only occurs if the file structure is changed outside of the RB- built application. This can lead to unexpected behavior, especially if an application watches a folder for changes.

To reproduce this, access a folderitem via RB code, then change the folderitem's contents in the Finder. Then access the folderitem via folderitem.item(n) and note that it returns incorrect values the first time. This is documented and illustrated in the sample project attached to:

<https://realsoftware.fogbugz.com/default.asp?4378_gm5u4lsa>

The simple workaround is to simply loop through the folderItem's items before you really need them. I have added a method called UpdateFolderItemCache that only does this:

Sub UpdateFolderItemCache(f as folderitem)
  if f = nil or not f.Exists then return
  dim ff as FolderItem
  dim i as Integer
   for i = f.Count downto 1
    ff = f.Item(i)
  next
End Sub

....and then folderitem.item(n) will work correctly (until the next time the folderitem changes).

Best wishes,

Steve

=========================================================
==     Stephen E. Hutson, AquilaDigital Partnership    ==
==              http://www.aquiladigital.us            ==
=========================================================


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>
  • FolderItem.Item Can Return Incorrect Results, Stephen E. Hutson <=