Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/Addressbook/Easy search
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/Easy search
This example is the version from Tue, 30th Jul 2012.
Project "Easy search.xojo_binary_project"
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control email Inherits TextField
ControlInstance email Inherits TextField
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control SearchButton Inherits PushButton
ControlInstance SearchButton Inherits PushButton
EventHandler Sub Action()
if CheckBox1.Value then
search2
else
search1
end if
End EventHandler
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
EventHandler Sub Open()
a=new abAddressbookMBS
End EventHandler
Sub search1()
// search records matching search element
dim p as new ABPersonMBS
list.deleteallrows
if email.text<>"" then
dim s as ABSearchElementMBS = ABAddressBookMBS.searchElementForPersonProperty(a.kABemailProperty,"","",email.text,a.kabcontainsSubStringCaseInsensitive)
if s<>nil then
dim ra() as ABRecordMBS = a.recordsMatchingSearchElement(s)
for each r as ABRecordMBS in ra
if r isa ABPersonMBS then
p=ABPersonMBS(r)
dim firstname as string = p.valueForProperty(a.kabfirstNameProperty)
dim lastname as string = p.valueForProperty(a.kablastNameProperty)
list.addrow firstname+" "+lastname
dim m as ABMultivalueMBS = p.valueForProperty(a.kABEmailProperty)
if m<>nil then
dim id as string = m.PrimaryIdentifier
if id<>"" then
list.cell(list.lastIndex,1)=m.valueAtIndex(m.IndexForIdentifier(id))
end if
end if
end if
next
else
beep
end if
else
beep
end if
End Sub
Sub search2()
// get all people and check each if it matches
dim s as ABSearchElementMBS
dim p as new ABPersonMBS
// this time we let the Addressbook search for a matching email address
list.deleteallrows
if email.text<>"" then
s = ABAddressBookMBS.searchElementForPersonProperty(a.kabemailproperty,"","",email.text,a.kabcontainsSubStringCaseInsensitive)
if s<>nil then
dim pa() as ABPersonMBS = a.people
for each p in pa
if s.matchesRecord(p) then
dim firstname as string = p.valueForProperty(a.kabfirstNameProperty)
dim lastname as string = p.valueForProperty(a.kablastNameProperty)
list.addrow firstname+" "+lastname
dim m as ABMultivalueMBS = p.valueForProperty(a.kABEmailProperty)
if m<>nil then
dim id as string = m.PrimaryIdentifier
if id<>"" then
list.cell(list.lastIndex,1)=m.valueAtIndex(m.IndexForIdentifier(id))
end if
end if
end if
next
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
The items on this page are in the following plugins: MBS MacCocoa Plugin.