Hello,
I have a window named CheckForVolumesWin which displays the icon for every mounted volume and if a volume is unmounted that icon disappears.
It worked well in Xojo 2019 Release 1 but I upgraded to macOS Monterey and Xojo 2019 Release 1 is not compatible so I am trying it in Xojo 2021 Release 2.1 but I am getting this error…
CheckForVolumesWin.CheckForVolumes, line 20
Type “FolderItem” has no member named “MacVRefNum”
j = Volume(i).MacVRefNum 'This is the key to differentiate 2 volumes (e.g, 2 volumes can be named “Macintosh HD”, with a different icon, and we want to remove the right one).
MacVRefNum was deprecated in version 2010r5. There is no replacement.
Here is the code:
Public Sub CheckForVolumes()
'Self.Width = 80
dim b As Boolean
Dim i,n as Integer
dim j,k,l As Integer
Dim NumberOfRows as integer
Dim IW as CImageWell
Dim ST as CStaticText
Dim S as String
S = ""
n = VolumeCount
NumberOfRows = Ceil(n/7)
'MsgBox "There will be " + Str(NumberOfRows) + " rows of mounted volumes"
if UBound(ListOfVolumes) = n-1 then Return 'No change
if UBound(ListOfVolumes) < n-1 then 'Volume mounted
//Here, we're going to find which volume is not in the list (the list is built every time a volume is added to the window):
For i = 0 to n-1
j = Volume(i).MacVRefNum 'This is the key to differentiate 2 volumes (e.g, 2 volumes can be named "Macintosh HD", with a different icon, and we want to remove the right one).
if ListOfVolumes.IndexOf(j)=-1 then 'Not in the known list, add it
IW = New myImageWell
IW.name = Volume(i).Name
If i < 7 then
IW.Top = 5
IW.Left = 16 + 69*(i)
IW.Width = 48
IW.Height = 48
IW.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
'S = S + chr(13) + "volume(" + str(i) + ") is " + IW.name + chr(13)
ST = New myStaticText
ST.name = Volume(i).Name + "ST"
ST.Top = 55
ST.Left = 10 + 69*(i)
ST.Width = 60
ST.Height = 12
ST.Text = Volume(i).Name.Left(4) + "..." + Volume(i).Name.Right(4)
ST.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
elseif i < 14 then
IW.Top = 5 + 76
IW.Left = 16 + 69*(i-7)
IW.Width = 48
IW.Height = 48
IW.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
'S = S + chr(13) + "volume(" + str(i) + ") is " + IW.name + chr(13)
CheckForVolumesWin.Height = 75 + 80
ST = New myStaticText
ST.name = Volume(i).Name + "ST"
ST.Top = 55 + 76
ST.Left = 10 + 69*(i-7)
ST.Width = 60
ST.Height = 12
ST.Text = Volume(i).Name.Left(4) + "..." + Volume(i).Name.Right(4)
ST.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
elseif i < 21 then
IW.Top = 5 + 76 + 76
IW.Left = 16 + 69*(i-7*2)
IW.Width = 48
IW.Height = 48
IW.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
'S = S + chr(13) + "volume(" + str(i) + ") is " + IW.name + chr(13)
CheckForVolumesWin.Height = 75 + 80*2
ST = New myStaticText
ST.name = Volume(i).Name + "ST"
ST.Top = 55 + 76 + 76
ST.Left = 10 + 69*(i-7*2)
ST.Width = 60
ST.Height = 12
ST.Text = Volume(i).Name.Left(4) + "..." + Volume(i).Name.Right(4)
ST.tag=Volume(i).MacVRefNum 'keep a reference (tag is from the defined class)
end if
Dim f as FolderItem
f = Volume(i)
Dim icon as MacIcon = MacIcon.NewIconFromFolderItem(f)
icon.size = 40
Dim p as Picture = icon
IW.Image = p
ListOfVolumes.Append j 'Add the volume to our list so we know it's known by us.
end if
Next
else 'volume ejected
//Determine which volume has been unmounted (which one is still in our list, but not in the volumes() array).
k=UBound(ListOfVolumes)
for i=k DownTo 0 'Reverse order in case 2 volumes have been ejected
b=False 'if b remains false, it means the volume was not in the list (see below)
for j=0 to n-1
if Volume(j).MacVRefNum=ListOfVolumes(i) then
b=true 'volume is in the list (still mounted and valid)
Exit
end if
Next
if not b then 'we found which volume has been ejected.
//Here, we won't delete static texts or image wells, because it will mess the correct ordering (e.g, say we have 5 disks, static texts and image wells and we remove the 2nd.
//Then, on new disk insertion, the new static text and image well will have an index of 2, which we don't want since the disk is the last in the list).
//Instead of deleting, we will first look for the item that was ejected, copy every static text and image well from there (the i+2 becomes the i+1, the i+3 becomes the i+2, etc)
//and delete the last one (we keep the same ordering).
l=0
b=False
do
IW=myImageWell(l)
if IW=nil then 'We are beyond the bounds (last index is l-1)
myImageWell(l-1).Close
myStaticText(l-1).Close
Exit 'do with next volume
end if
if b then 'we found the volume that was ejected. We "push up" every static text and image well to make the last one the one we will remove.).Image
myImageWell(l-1).Image=myImageWell(l).Image
myStaticText(l-1).Text=myStaticText(l).Text
myImageWell(l-1).Tag=myImageWell(l).Tag
myStaticText(l-1).Tag=myStaticText(l).Tag
end if
if IW.Tag=ListOfVolumes(i) then
b=True 'happens when the item is the one we ewants (the one which was ejected). This actually happens "before" the block of code just above ("if b then"), but on the next iteration of the loop
end if
l=l+1
loop
ListOfVolumes.Remove i
end if
Next
end if
self.Refresh
'Self.Width = 80 + 69*(UBound(ListOfVolumes))
Self.Width = 485
'Self.Left = Window1.Left
'EditField1.Text = Trim(S)
CheckForVolumesWin.refresh 'We don't know it anymore
End Sub
How can I fix that?
Thanks.
Lennox