In the DropObject Event, we can process (if there is more than one dropped item) more than one dropped item.
In a proof of concept, earlier today, I realized that I have to put twice the same code (proof of concept, not optimized code) to get all items.
Am I Wrong ?
Or was my early morning coffee not only coffee ?
Imagine a stupid code that only adds the dropped item file name into a ListBox:
Code #1:
// Dealing with the first (or only) dropped item
LB.AddRow Obj.FolderItem.DisplayName
Code #2:
While Obj.NextItem
// Dealing with all other dropped items
LB.AddRow Obj.FolderItem.DisplayName // That will be 10 dropped files max
no need to use InsertRow to speed it up
Wend
I checked (maybe I was wrong) with removing the code #1, but the dropped item #1 was skipped.
for multiple Files I use
if obj.FolderItemAvailable then
do
lb.AddRow obj.FolderItem.DisplayName
loop until not obj.NextItem
end if
or with scanning subfolders
if obj.FolderItemAvailable then
do
ScanFiles obj.FolderItem
loop until not obj.NextItem
end if
Method
dim name as text = file.name.ToText
if file.directory then
for i as integer = 1 to file.count
ScanFiles file.item(i)
next
else
if name.BeginsWith(".") = false then
LB.AddRow name
end if
end
cannot edit
Method is
Sub ScanFiles(file as folderItem)
dim name as text = file.name.ToText
if file.directory then
for i as integer = 1 to file.count
ScanFiles file.item(i)
next
else
if name.BeginsWith(".") = false then
lb.AddRow name
lb.Cell(lb.LastIndex, 1) = file.NativePath
end if
end
End Sub
[quote=194373:@Emile Schwarz]
While Obj.NextItem
// Dealing with all other dropped items
LB.AddRow Obj.FolderItem.DisplayName // That will be 10 dropped files max
no need to use InsertRow to speed it up
Wend
I checked (maybe I was wrong) with removing the code #1, but the dropped item #1 was skipped.[/quote]
Obj.NextItem
advances to the next item, if any. You need to test it at the end of the loop otherwise the first item is skipped:
Do
If Obj.FolderItem Then
LB.AddRow Obj.FolderItem.DisplayName
End If
Loop Until Not Obj.NextItem
Thanks for your advices.
Andrew wrotes:
Obj.NextItem
advances to the next item, if any. You need to test it at the end of the loop otherwise the first item is skipped.
THIS HAVE TO BE IN THE DOCUMENTATION, eventually.
DragItem.NextItem.
A third read of Andrews answer revealed how wrong I was and how nice his code is.
My current code works fine, but Andrews advice seems nice: I will check it.
Without code checking, my current code store the reference to all dropped files into a global FolderItem array property, then it calls the Method who will process the files.
This looks far nice to my eyes.
Current code (simili code):
[code]ImagesFI.Append Obj.FolderItem // Store the first dropped file reference
While Obj.NextItem // Store every other dropped file reference
ImagesFI.Append Obj.FolderItem
Wend
Process_Files() // This will scan teh array and do the job with each found file[/code]
Nota: ImagesFI(0)
is Nil
; ImagesFI(1)
holds the first dropped image.
Yes, I do not checked if the dropped file(s) is/are of the correct type, etc. (no error checkings). The purpose is to show working code / sharing ideas.
I just made a google quest on +“Loop Until Not Obj.NextItem”
and get an answer (in French) that dates from 2000-08-14 !!! here .
I also get another from an old friend: REALBasic: TDG: The Definitive Guide, 2nd Edition
.
What a pity.
First implementation:
[code] #Pragma Unused action
Do
If Obj.FolderItemAvailable Then
ImagesFI.Append Obj.FolderItem
End If
Loop Until Not Obj.NextItem
// Now, process the images
Process_Images
Return[/code]
Note: I made a change in the If Then line and adapted the code in the block to fit my need.
Result: the first dropped file (image) is lost.
Fortunately, I made a version to display 2 Rows / 5 columns with their file names drawn below each cover image. I dropped 10 images and get only 9.
BTW: I had many troubles while writing the code; as an example, I set a 20 pixels margin between each image (horizontally) and I get 30 pixels
so I set 10 to get 20
who can understand ? I use x,y in the Process_Image() method which does not have a lot of lines / x and y values are modified in 4 contigous lines (one single line and 3 lines in an If block).
I also have the file name below the last image that appears
or not without understandable change (I do not understand why the file name appears or disappears while I made other non-related changes in the same method).
My previous code (who works fine):
[code] ReDim ImagesFI(0)
// Add the first dropped image into the array
ImagesFI.Append Obj.FolderItem
// Add all other dropped files into the array
While Obj.NextItem
ImagesFI.Append Obj.FolderItem
Wend
// Now, process the images
Process_Images[/code]
Heres an example of what I am talking to (doing):
The front cover (images) comes fro an Australian comic magazine (Frew).
I also create mosaics from icons (128 pixels heigh / one year of weekly issues + specials: 55 covers max).