How to path to a Canvas' dropped object?

Hi,
I have the code below in a segmented control’s action event.
It obviously produces a THIS ITEM DOES NOT EXIST error, because the obj refers to canvas1.

My question is - how do I path to a dropped object in Canvas1 from the segmented control??

// CHECK IF AN IMAGE WAS DROPPED ONTO CANVAS1 if obj.FolderItemAvailable and not obj.FolderItem.Directory then MsgBox("Hello World") End if

Thanks.

In the Canvas1.DropObject event I have now added the following code:

// SET THE DROPPED IMAGE TO THE PROPERTY CALLED droppedFolderItem droppedFolderItem = obj.FolderItem

And created a property in a module called droppedFolderItem (type FolderItem), but I am now unsure what the following code should be changed to?

// CHECK IF AN IMAGE WAS DROPPED ONTO CANVAS1 if obj.FolderItemAvailable and not obj.FolderItem.Directory then MsgBox("Hello World") End if

Do you mean this?

if obj.FolderItemAvailable and obj.FolderItem <> nil and obj.FolderItem.Exists then 'do something with obj.Folderitem end if

Remember last week, variables that are only available within a particular event ?

Yes, that’s why I added a property in a module, to hold the obj.folderItem, and then be able to call it from elsewhere.
But I have obviously gone wrong somewhere?

Likely. Grin… But we can’t see your code and there is still no telepathy module.

I posted my code above?
Post 2 :slight_smile:

Basically my window contains Canvas1, which when a user drops an image onto it, the canvas displays that image.
All works perfectly.

But I need to be able to refer to the dropped object from elsewhere (a segmented control).
So I add the following code to the canvas1.DropObject code:

// SET THE DROPPED IMAGE TO THE PROPERTY CALLED droppedFolderItem droppedFolderItem = obj.FolderItem

And also created a property in a module called droppedFolderItem (type FolderItem), but I am now unsure what the following code should be changed to?

if obj.FolderItemAvailable and not obj.FolderItem.Directory then

Hope that made more sense?
:slight_smile:

[quote=108688:@Richard Summers]Yes, that’s why I added a property in a module, to hold the obj.folderItem, and then be able to call it from elsewhere.
But I have obviously gone wrong somewhere?[/quote]

Maybe you need to call your module variable name instead of “obj”.

You mean like this?

If droppedFolderItem.folderItemAvailable and not droppedFolderItem.FolderItem.Directory then

If so, then that made no difference - still get the same does not exist error.

[quote=108701:@Richard Summers]You mean like this?

If droppedFolderItem.folderItemAvailable and not droppedFolderItem.FolderItem.Directory then

If so, then that made no difference - still get the same does not exist error.[/quote]

Richard, you are trying to use in the Action event properties that are not available there for your FolderItem variable …

So basically I cannot check to see if an item has been dropped, or if it is a directory because those properties are not available in the segmented control, only for the canvas.

So my question now is - how do I get access to those properties, if I am in a segmented control?

Once you have saved the folderitem, check it for nil. You will eventually want to reset it, but if you want to access the last item dropped on the canvas, use

if droppedFolderItem <> nil then
   // do something with droppedFolderItem
end

It is not necessary to check obj.FolderItemAvailable from the segmented control. The presence or absence of droppedFolderItem implies that information. In other words, if droppedFolderItem is nil, then nothing has been dropped on the canvas. If it is not nil, then obviously, something has been dropped. The only issue is, how long do you want droppedFolderItem to live? How long before that information becomes “stale”.

Thank you so much!