Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Addressbook/Group members
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Addressbook/Group members
This example is the version from Tue, 30th Jul 2012.
Project "Group members.rbp"
Class MainWindow Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
EventHandler Sub ExpandRow(row As Integer) dim o as ABGroupMBS o=me.CellTag(row,0) if o<>Nil then dim ga() as ABGroupMBS = o.subgroups for each g as ABGroupMBS in ga AddGroup g next dim pa() as ABPersonMBS = o.members for each p as ABPersonMBS in pa AddPerson p next end if End EventHandler
End Control
EventHandler Sub Close() List.DeleteAllRows // remove references to objects before ABAddressBookMBS object is destroyed End EventHandler
EventHandler Sub Open() a=new abAddressbookMBS dim ga() as ABGroupMBS = a.groups for each g as ABGroupMBS in ga AddGroup g next End EventHandler
Sub AddGroup(g as abgroupmbs) dim name as string name=g.valueForProperty(a.kABGroupNameProperty) List.AddFolder name List.celltag(List.LastIndex,0)=g End Sub
Sub AddPerson(p as abpersonmbs) dim name,email as string dim emails as ABMultiValueMBS name=p.valueForProperty(a.kABFirstNameProperty)+" "+p.valueForProperty(a.kABLastNameProperty) if name = " " then name = p.valueForProperty(a.kABOrganizationProperty) end if List.AddRow name List.celltag(List.LastIndex,0)=p emails=p.valueForProperty(a.kABEmailProperty) if emails<>Nil then email=emails.valueAtIndex(emails.indexForIdentifier(emails.primaryIdentifier)) List.cell(List.LastIndex,1)=email end if End Sub
Sub search() 'dim s as ABGroupMBS 'dim p as ABPersonMBS 'dim pa as ABPersonArrayMBS 'dim i,c,l as integer 'dim m as ABMultiMBS 'dim id as CFStringMBS 'dim index as integer 'dim z,t as string 'dim tt as CFStringMBS ' '// this time we let the Addressbook search for a matching email address ' 'list.deleteallrows 't=PopupMenu1.RowTag(PopupMenu1.ListIndex) ''setstringEncoding t,0 'if t<>"" then 'tt=NewCFStringMBS(t) 's=a.Group(tt) ' 'if s<>nil then 'pa=s.AllMembers 'if pa<>nil then 'c=pa.count-1 'for i=0 to c 'p=pa.Person(i) 'if p<>nil then 't=st(p.GetValue(a.kabfirstNameProperty))+" "+st(p.getValue(a.kablastNameProperty)) ''msgBox str(len(T))+" "+str(lenb(t))+" "+t ''setstringEncoding t,256 // Fix bug in RB 4.5b3 'list.addrow t 'l=list.lastIndex 'm=p.getmultiValue(a.kABEmailProperty) 'if m<>nil then 'id=m.PrimaryIdentifier 'if id<>Nil then 'index=m.IndexForIdentifier(id) 'list.cell(l,1)=st(m.Value(index)) 'end if 'end if 'end if 'next 'else 'beep 'end if 'else 'beep 'end if 'else 'beep 'end if End Sub
Property a As abaddressbookMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO=false then MsgBox "This example needs a MachO target running on Mac OS X." quit end if End EventHandler
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.

MBS Xojo Plugins