Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Addressbook/Search Person
Function:
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/Search Person
This example is the version from Tue, 30th Jul 2012.
Project "Search Person.rbp"
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control lastname Inherits TextField
ControlInstance lastname Inherits TextField
EventHandler Sub TextChange() pushLastname.enabled=me.text<>"" End EventHandler
End Control
Control PushLastname Inherits PushButton
ControlInstance PushLastname Inherits PushButton
EventHandler Sub Action() dim s as ABSearchElementMBS dim n as string dim p as new ABPersonMBS dim x as integer list.deleteAllRows n=lastname.text s = ABAddressBookMBS.searchElementForPersonProperty(a.kABLastNameProperty,"","",n,a.kABContainsSubStringCaseInsensitive) if s<>nil then showlist a.recordsMatchingSearchElement(s) else msgBox "Can't make a Search object." end if End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control email Inherits TextField
ControlInstance email Inherits TextField
EventHandler Sub TextChange() pushemail.enabled=me.text<>"" End EventHandler
End Control
Control PushEmail Inherits PushButton
ControlInstance PushEmail Inherits PushButton
EventHandler Sub Action() dim s as ABSearchElementMBS dim p as new ABPersonMBS dim n as string dim label as string list.deleteAllRows n=email.text // msgBox str(getstringencoding(n)) // A bug in some RB 4.5 let t be nil, because the string encoding is set to a bad value. // setstringEncoding n,0 // To repair this, set the encoding to 0, which is MacRoman or to 256 for Unicode in 16bit. select case popupMenu1.listindex case 1 // Work label=a.kABEmailWorkLabel case 2 // Home label=a.kABEmailHomeLabel else label="" end select s = ABAddressBookMBS.searchElementForPersonProperty(a.kABEmailProperty,Label,"",n,a.kABContainsSubStringCaseInsensitive) if s<>nil then showlist a.recordsMatchingSearchElement(s) else msgBox "Can't make a Search object." end if End EventHandler
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
End Control
EventHandler Sub Open() a=new abAddressbookMBS End EventHandler
Sub showlist(ra() as ABRecordMBS) for each r as ABRecordMBS in ra if r isa ABPersonMBS then dim p as ABPersonMBS = ABPersonMBS(r) dim uid as string = p.valueForProperty(a.kABUIDProperty) list.addrow uid dim l as integer = list.lastIndex list.cell(l,1)=p.valueForProperty(a.kABFirstNameProperty) list.cell(l,2)=p.valueForProperty(a.kABLastNameProperty) // gettting the primary email address is a little bit compilcate: dim m as ABMultiValueMBS = p.valueForProperty(a.kABEmailProperty) if m<>Nil then dim found as boolean = false select case popupMenu1.listindex case 1 // Search the work address dim n as integer = m.Count-1 for j as integer = 0 to n if m.labelAtIndex(j)=a.kABEmailWorkLabel then list.cell(l,3)=m.valueAtIndex(j) found=true end if next case 2 // Search the home address dim n as integer = m.Count-1 for j as integer = 0 to n if m.labelAtIndex(j)=a.kABEmailHomeLabel then list.cell(l,3)=m.valueAtIndex(j) found=true end if next end select // Else search the primary one if not found then dim id as string = m.PrimaryIdentifier if id<>"" then dim index as integer = m.IndexForIdentifier(id) list.cell(l,3)=m.valueAtIndex(index) end if end if end if end if next End Sub
Property Protected 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.





Links
MBS Xojo Chart Plugins