📄 phbsearch.pas
字号:
unit phbsearch;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, ComCtrls,global;
type
TForm_phbsearch = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
Bevel1: TBevel;
ListView_phbsearch: TListView;
Edit_searchname: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure ListView_phbsearchColumnClick(Sender: TObject;
Column: TListColumn);
procedure FormActivate(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
FLastIndex_phonebook:Integer;
// FLastViewState_phonebook:TViewState_PHB;
procedure ListView_phbsearchSort(sort:string);
procedure ListView_SearchPHBK(name:string);
public
{ Public declarations }
end;
var
Form_phbsearch: TForm_phbsearch;
implementation
{$R *.dfm}
function CustSortAsc(Item1, Item2:TListItem;ColIndex: Integer): Integer; stdcall;
var
Item1Str:string;
Item2Str:string;
begin
Result := 0;
Item1Str :='';
Item2Str :='';
if ColIndex < 0 then Exit;
if ColIndex = 0 then
begin
Item1Str := Item1.Caption;
Item2Str := Item2.Caption;
end
else
begin
if ColIndex <= Item1.SubItems.Count then
Item1Str := Item1.SubItems[ColIndex - 1];
if ColIndex <= Item2.SubItems.Count then
Item2Str := Item2.SubItems[ColIndex - 1];
end;
Result := CompareText(Item1Str, Item2Str);
// If one of the strings is empty, make the other string sort before it
if (Result > 0) and (Item2Str = '') then Result := -1
else
if (Result < 0) and (Item1Str ='') then Result := 1;
end; {= CustSortAsc =}
function CustSortDesc(Item1, Item2: TListItem;ColIndex: Integer): Integer; stdcall;
begin
Result := CustSortAsc(Item1, Item2, ColIndex);
Result := Result*-1;
end; {= CustSortDesc =}
procedure TForm_phbsearch.ListView_phbsearchSort(sort:string);
var i:integer;
tempitem:TListItem;
tempPHB:PPhoneBook;
begin
ListView_phbsearch.Visible:=false;
ListView_phbsearch.Items.Clear;
for i:=0 to PhoneBookList.count-1 do
begin
tempPHB:=PPhoneBook(PhoneBookList[i]);
if sort<>'' then
if tempPHB.Location<>sort then continue;
tempitem:=ListView_phbsearch.Items.Add;
tempitem.Caption:=tempPHB.SN;
tempitem.SubItems.Add(tempPHB.Name);
tempitem.SubItems.Add(tempPHB.number);
end;
ListView_phbsearch.Visible:=true;
end;
procedure TForm_phbsearch.ListView_SearchPHBK(name:string);
var i:integer;
tempitem:TListItem;
tempPHB:PPhoneBook;
begin
ListView_phbsearch.Visible:=false;
ListView_phbsearch.Items.Clear;
for i:=0 to PhoneBookList.count-1 do
begin
tempPHB:=PPhoneBook(PhoneBookList[i]);
if pos(name,tempPHB.name)=0 then continue;
tempitem:=ListView_phbsearch.Items.Add;
tempitem.Caption:=tempPHB.SN;
tempitem.SubItems.Add(tempPHB.Name);
tempitem.SubItems.Add(tempPHB.number);
end;
ListView_phbsearch.Visible:=true;
end;
procedure TForm_phbsearch.ListView_phbsearchColumnClick(Sender: TObject;
Column: TListColumn);
begin
if FLastIndex_phonebook = Column.Index then
begin
ListView_phbsearch.CustomSort(@CustSortDesc, Column.Index);
FLastIndex_phonebook := -1;
end else
begin
ListView_phbsearch.CustomSort(@CustSortAsc, Column.Index);
FLastIndex_phonebook := Column.Index;
end;
end;
procedure TForm_phbsearch.FormActivate(Sender: TObject);
begin
ListView_phbsearchSort('');
end;
procedure TForm_phbsearch.OKBtnClick(Sender: TObject);
begin
if (ListView_phbsearch.Selected<>nil) then
ModalResult:=mrOK
else
ModalResult:=mrCancel;
end;
procedure TForm_phbsearch.BitBtn2Click(Sender: TObject);
begin
ListView_phbsearchSort('');
end;
procedure TForm_phbsearch.BitBtn1Click(Sender: TObject);
begin
if trim(Edit_searchname.Text)<>'' then
ListView_SearchPHBK(trim(Edit_searchname.Text));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -