P
porsche
Unregistered / Unconfirmed
GUEST, unregistred user!
很久没有上来过了,今天写了个控件,希望对大家实际工作中能有所帮助
用途:在编程工作中,经常有要输入姓名或从一大堆的姓名或者分类中选择一个的情况。
使用方法:在AllList中定义下拉框中的内容,在ComboBox中输入拼音首字母或汉字,下拉列表中显示相匹配的条目
代码:
//**********************
//Author:朱红波
//Email:4719373@163.com
//Time:2004-06-03
//**********************
unit ComboBoxPY;
interface
uses
Windows,Messages,SysUtils,Classes,Controls,StdCtrls,DBCtrls;
function SearchByPY(SourceStr:TStringList;PYStr:string):string;
//***********************************
type
TComboBoxPY=class(TComboBox)
private
FAllList:TStringList;
procedure SetAllList(Value:TStringList);
protected
procedure Change; override;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property AllList:TStringList read FAllList write SetAllList;
end;
//end type TComboBoxPY
//***********************************
type
TDBComboBoxPY=class(TDBComboBox)
private
FAllList:TStringList;
procedure SetAllList(Value:TStringList);
protected
procedure Change; override;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property AllList:TStringList read FAllList write SetAllList;
end;
//end type TDBComboBoxPY
procedure Register;
implementation
function SearchByPY(SourceStr:TStringList;PYStr:string):string;
function GetPYIndexChar(hzchar:string):char;
begin
case WORD(hzchar[1])shl 8+WORD(hzchar[2]) of
$B0A1..$B0C4:result:='A';$B0C5..$B2C0:result:='B';
$B2C1..$B4ED:result:='C';$B4EE..$B6E9:result:='D';
$B6EA..$B7A1:result:='E';$B7A2..$B8C0:result:='F';
$B8C1..$B9FD:result:='G';$B9FE..$BBF6:result:='H';
$BBF7..$BFA5:result:='J';$BFA6..$C0AB:result:='K';
$C0AC..$C2E7:result:='L';$C2E8..$C4C2:result:='M';
$C4C3..$C5B5:result:='N';$C5B6..$C5BD:result:='O';
$C5BE..$C6D9:result:='P';$C6DA..$C8BA:result:='Q';
$C8BB..$C8F5:result:='R';$C8F6..$CBF9:result:='S';
$CBFA..$CDD9:result:='T';$CDDA..$CEF3:result:='W';
$CEF4..$D188:result:='X';$D1B9..$D4D0:result:='Y';
$D4D1..$D7F9:result:='Z';
else
result:=char(0);
end;
end;
label NotFound;
var
i,j:integer;
hzchar:string;
begin
for i:=0 to SourceStr.Count-1 do
begin
for j:=1 to Length(PYStr) do
begin
hzchar:=SourceStr[2*j-1]+SourceStr[2*j];
if (PYStr[j]<>'?')and(UpperCase(PYStr[j])<>GetPYIndexChar(hzchar)) then
goto NotFound;
end;
if Result='' then Result:=SourceStr
else Result:=Result+Char(13)+SourceStr;
NotFound:
end;
end;
//TComboBoxPY*********************************************************
constructor TComboBoxPY.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FAllList:=TStringList.Create;
Self.Sorted:=True;
Self.AutoDropDown:=True;
end;
destructor TComboBoxPY.Destroy;
begin
FAllList.Free;
inherited Destroy;
end;
procedure TComboBoxPY.SetAllList(Value:TStringList);
begin
if AllList.Text<>Value.Text then
begin
AllList.Text:=Value.Text;
Items.Text:=Value.Text;
end;
end;
procedure TComboBoxPY.Change;
begin
Self.DropDownCount:=8;
Self.AutoDropDown:=False;
if ByteType(Self.Text,1)=mbSingleByte then //mbLeadByte then
begin
Self.Items.Text:=SearchByPY(AllList,Self.Text);
keybd_event(VK_END,0,0,0);
end;
Self.AutoDropDown:=True;
inherited;
end;
//TDBComboBoxPY*********************************************************
constructor TDBComboBoxPY.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FAllList:=TStringList.Create;
Self.Sorted:=True;
Self.AutoDropDown:=True;
end;
destructor TDBComboBoxPY.Destroy;
begin
FAllList.Free;
inherited Destroy;
end;
procedure TDBComboBoxPY.SetAllList(Value:TStringList);
begin
if AllList.Text<>Value.Text then
begin
AllList.Text:=Value.Text;
Items.Text:=Value.Text;
end;
end;
procedure TDBComboBoxPY.Change;
begin
Self.DropDownCount:=8;
Self.AutoDropDown:=False;
if ByteType(Self.Text,1)=mbSingleByte then
begin
Self.Items.Text:=SearchByPY(AllList,Self.Text);
keybd_event(VK_END,0,0,0);
end;
Self.AutoDropDown:=True;
inherited;
end;
procedure Register;
begin
RegisterComponents('porsche', [TComboBoxPY,TDBComboBoxPY]);
end;
end.
用途:在编程工作中,经常有要输入姓名或从一大堆的姓名或者分类中选择一个的情况。
使用方法:在AllList中定义下拉框中的内容,在ComboBox中输入拼音首字母或汉字,下拉列表中显示相匹配的条目
代码:
//**********************
//Author:朱红波
//Email:4719373@163.com
//Time:2004-06-03
//**********************
unit ComboBoxPY;
interface
uses
Windows,Messages,SysUtils,Classes,Controls,StdCtrls,DBCtrls;
function SearchByPY(SourceStr:TStringList;PYStr:string):string;
//***********************************
type
TComboBoxPY=class(TComboBox)
private
FAllList:TStringList;
procedure SetAllList(Value:TStringList);
protected
procedure Change; override;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property AllList:TStringList read FAllList write SetAllList;
end;
//end type TComboBoxPY
//***********************************
type
TDBComboBoxPY=class(TDBComboBox)
private
FAllList:TStringList;
procedure SetAllList(Value:TStringList);
protected
procedure Change; override;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property AllList:TStringList read FAllList write SetAllList;
end;
//end type TDBComboBoxPY
procedure Register;
implementation
function SearchByPY(SourceStr:TStringList;PYStr:string):string;
function GetPYIndexChar(hzchar:string):char;
begin
case WORD(hzchar[1])shl 8+WORD(hzchar[2]) of
$B0A1..$B0C4:result:='A';$B0C5..$B2C0:result:='B';
$B2C1..$B4ED:result:='C';$B4EE..$B6E9:result:='D';
$B6EA..$B7A1:result:='E';$B7A2..$B8C0:result:='F';
$B8C1..$B9FD:result:='G';$B9FE..$BBF6:result:='H';
$BBF7..$BFA5:result:='J';$BFA6..$C0AB:result:='K';
$C0AC..$C2E7:result:='L';$C2E8..$C4C2:result:='M';
$C4C3..$C5B5:result:='N';$C5B6..$C5BD:result:='O';
$C5BE..$C6D9:result:='P';$C6DA..$C8BA:result:='Q';
$C8BB..$C8F5:result:='R';$C8F6..$CBF9:result:='S';
$CBFA..$CDD9:result:='T';$CDDA..$CEF3:result:='W';
$CEF4..$D188:result:='X';$D1B9..$D4D0:result:='Y';
$D4D1..$D7F9:result:='Z';
else
result:=char(0);
end;
end;
label NotFound;
var
i,j:integer;
hzchar:string;
begin
for i:=0 to SourceStr.Count-1 do
begin
for j:=1 to Length(PYStr) do
begin
hzchar:=SourceStr[2*j-1]+SourceStr[2*j];
if (PYStr[j]<>'?')and(UpperCase(PYStr[j])<>GetPYIndexChar(hzchar)) then
goto NotFound;
end;
if Result='' then Result:=SourceStr
else Result:=Result+Char(13)+SourceStr;
NotFound:
end;
end;
//TComboBoxPY*********************************************************
constructor TComboBoxPY.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FAllList:=TStringList.Create;
Self.Sorted:=True;
Self.AutoDropDown:=True;
end;
destructor TComboBoxPY.Destroy;
begin
FAllList.Free;
inherited Destroy;
end;
procedure TComboBoxPY.SetAllList(Value:TStringList);
begin
if AllList.Text<>Value.Text then
begin
AllList.Text:=Value.Text;
Items.Text:=Value.Text;
end;
end;
procedure TComboBoxPY.Change;
begin
Self.DropDownCount:=8;
Self.AutoDropDown:=False;
if ByteType(Self.Text,1)=mbSingleByte then //mbLeadByte then
begin
Self.Items.Text:=SearchByPY(AllList,Self.Text);
keybd_event(VK_END,0,0,0);
end;
Self.AutoDropDown:=True;
inherited;
end;
//TDBComboBoxPY*********************************************************
constructor TDBComboBoxPY.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FAllList:=TStringList.Create;
Self.Sorted:=True;
Self.AutoDropDown:=True;
end;
destructor TDBComboBoxPY.Destroy;
begin
FAllList.Free;
inherited Destroy;
end;
procedure TDBComboBoxPY.SetAllList(Value:TStringList);
begin
if AllList.Text<>Value.Text then
begin
AllList.Text:=Value.Text;
Items.Text:=Value.Text;
end;
end;
procedure TDBComboBoxPY.Change;
begin
Self.DropDownCount:=8;
Self.AutoDropDown:=False;
if ByteType(Self.Text,1)=mbSingleByte then
begin
Self.Items.Text:=SearchByPY(AllList,Self.Text);
keybd_event(VK_END,0,0,0);
end;
Self.AutoDropDown:=True;
inherited;
end;
procedure Register;
begin
RegisterComponents('porsche', [TComboBoxPY,TDBComboBoxPY]);
end;
end.