如何得到汉字的五笔首字符?(100) ( 积分: 100 )

  • 主题发起人 主题发起人 corely
  • 开始时间 开始时间
C

corely

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,如果有相关控件也行,小弟做东东时需要但不知道怎么处理
 
如题,如果有相关控件也行,小弟做东东时需要但不知道怎么处理
 
我以前写过一个控件,可以得到五笔码,拼音,汉语拼音....
源码是在下面,你可以参考下.(源码还需要wbtext.res文件,这里不能上传文件,需要的话请与我联系)
很久前写的代码,写得不好,:)
//作者:杨勇 (oiwin)
//有问题请联系,谢谢.
//QQ:440881

unit OWGetBM;

interface

uses
Windows, Messages, SysUtils, Classes;
type
TOWGetBM = class(TComponent)
private
{ Private declarations }
FHZString, FPYString, FWBString, FHYPYString, FQWString, FJTString, FFTString: string;
procedure GetPYString(s: string);
procedure GetHYPYString(s: string);
procedure GetWBString(s: string);
procedure GetQWString(s: string);
procedure GetJTString(s: string);
procedure GetFTString(s: string);
procedure SetHZString(s: string);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent)
override;
destructor Destroy
override;
published
{ Published declarations }
property HZString: string read FHZString write SetHzString;
property PYString: string read FPYString write GetPYString;
property WBString: string read FWBString write GetWBString;
property HYPYString: string read FHYPYString write GetHYPYString;
property JTString: string read FJTString write GetJTString;
property FTString: string read FFTString write GetFTString;
property QWString: string read FQWString write GetQWString;
end;

procedure Register;

implementation
{$R wbtext.res}

constructor TOWGetBM.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHZString := '';
end;

destructor TOWGetBM.Destroy;
begin
inherited Destroy;
end;

procedure TOWGetBM.SetHZString(s: string);
begin
if (FHZString <> s) then
begin
FHZString := s;
GetPYString(FHZString);
GetHYPYString(FHZString);
GetWBString(FHZString);
GetQWString(FHZString);
GetJTString(FHZString);
GetFTString(FHZString);
end;
end;

function get_hz_pywb(hzstr: string
pytype: integer): string;
var
hh: THandle;
pp: pointer;
I: Integer;
allstr: string;
FBMTable: TStringList;
function retturn_wbpy(tempstr: string
tqtype: integer): string;
var
str: string;
i: integer;
begin
i := 0;
while i < FBMTable.Count do
begin
str := FBMTable.Strings;
if (tempstr = str[1] + str[2]) or (tempstr = str[3] + str[4]) then
Break;
i := i + 1;
end;
if i < FBMTable.Count then
case tqtype of
1: Result := copy(str, 5, pos('|', str) - 5) + ' ';
2: Result := copy(str, pos('|', str) + 1, pos('~', str) - pos('|', str) - 1) + ' ';
3: Result := str[3] + str[4];
4: Result := str[1] + str[2];
5: Result := copy(str, pos('~', str) + 1, length(str) - pos('~', str)) + ' ';
end
else
Result := tempstr;
end;

begin
FBMTable := TStringList.Create;
hh := FindResource(hInstance, 'mywb', 'TXT');
hh := LoadResource(hInstance, hh);
pp := LockResource(hh);
FBMTable.Text := pchar(pp);
UnLockResource(hh);
FreeResource(hh);
allstr := '';
i := 0;
while i <= length(hzstr) do
begin
if (Ord(hzstr) > 127) then
begin
allstr := allstr + retturn_wbpy(hzstr + hzstr[I + 1], pytype);
inc(i);
end
else
allstr := allstr + hzstr;
inc(i);
end;
FBMTable.Free;
Result := trim(allstr);
end;

function hzToqwstr(const hzstr: string): string;
var
i: integer;
function hztoqw(const shz: string): string;
var
qu, wei: integer;
begin
qu := ord(shz[1]);
wei := ord(shz[2]);
result := '';
if (qu - 160) < 10 then
result := '0';
result := result + inttostr(qu - 160);
if (wei - 160) < 10 then
result := result + '0';
result := inttohex(qu, 2) + inttohex(wei, 2);
end;
begin
i := 0;
result := '';
while i <= length(hzstr) do
begin
if (Ord(hzstr) > 127) then
begin
result := result + hztoqw(hzstr + hzstr[I + 1]) + ' ';
inc(i);
end
else
result := result + format('%2x', [ord(hzstr)]) + ' ';
inc(i);
end;
result := copy(result, 4, length(result) - 4);
end;

procedure TOWGetBM.GetPYString(s: string);
begin
FPYString := get_hz_pywb(FHZString, 5);
end;

procedure TOWGetBM.GetWBString(s: string);
begin
FWBString := get_hz_pywb(FHZString, 2);
end;

procedure TOWGetBM.GetHYPYString(s: string);
begin
FHYPYString := get_hz_pywb(FHZString, 1);
end;

procedure TOWGetBM.GetJTString(s: string);
begin
FJTString := get_hz_pywb(FHZString, 4);
end;

procedure TOWGetBM.GetFTString(s: string);
begin
FFTString := get_hz_pywb(FHZString, 3);
end;

procedure TOWGetBM.GetQWString(s: string);
begin
FQWString := hzToqwstr(FHZString);
end;

procedure Register;
begin
RegisterComponents('oiwin', [TOWGetBM]);
end;

end.
 
你可以直接用控件
 
接受答案了.
 
后退
顶部