tvplanit: Search contact by first and last name.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8433 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-31 21:09:35 +00:00
parent 9c4260cd4e
commit 18308fa2bb

View File

@ -493,8 +493,8 @@ type
function Count: Integer;
procedure DeleteContact(Contact: TVpContact);
function First: TVpContact;
function FindContactByName(const AName: string;
CaseInsensitive: Boolean = True): TVpContact;
function FindContactByName(const AName: string; CaseInsensitive: Boolean = True): TVpContact; overload;
function FindContactByName(const AFirstName, ALastName: string; CaseInsensitive: Boolean = True): TVpContact; overload;
function FindContactIndexByName(const Name: string;
CaseInsensitive: Boolean = True): Integer;
function GetContact(Index: Integer): TVpContact;
@ -2987,9 +2987,10 @@ begin
end;
end;
{ new function introduced to support the new buttonbar component. }
{ Function introduced to support the new buttonbar component.
Performs a search for a contact by its partial last name. }
function TVpContacts.FindContactByName(const AName: string;
CaseInsensitive: Boolean): TVpContact;
CaseInsensitive: Boolean = true): TVpContact;
var
I: Integer;
SearchStr: String;
@ -3018,7 +3019,48 @@ begin
end;
end;
{ new function introduced to support the new buttonbar component }
{ This overload of FindContactByName performs another search for a contact,
but now on complete first and last names. }
function TVpContacts.FindContactByName(const AFirstName, ALastName: string;
CaseInsensitive: Boolean = true): TVpContact;
var
I: Integer;
SearchStr1, SearchStr2: String;
SearchName1, SearchName2: String;
contact: TVpContact;
begin
Result := nil;
// To enhance performance, uppercase the input name and get its length only once
if CaseInsensitive then
begin
SearchStr1 := UpperCase(AFirstName);
SearchStr2 := UpperCase(ALastName);
end else
begin
SearchStr1 := AFirstName;
SearchStr2 := ALastName;
end;
// Iterate the contacts looking for a match
for I := 0 to FContactsList.Count - 1 do begin
contact := TVpContact(FContactsList[I]);
SearchName1 := contact.FirstName;
SearchName2 := contact.LastName;
if CaseInsensitive then
begin
SearchName1 := Uppercase(SearchName1);
SearchName2 := Uppercase(SearchName2);
end;
// We found a match, so return it and bail out
if (SearchName1 = SearchStr1) and (SearchName2 = SearchStr2) then begin
Result := TVpContact(FContactsList[I]);
exit;
end;
end;
end;
{ new function introduced to support the new buttonbar component }
function TVpContacts.FindContactIndexByName(const Name: string;
CaseInsensitive: Boolean): Integer;
var