delphi 如何获取edit的text中的每个汉字首字母呢?

我需要获取个edit中的text内容里的汉字首字母加在一起组成一个编码赋值给另外一个edit在网上查询过之前的获取方法,都是一个写出来的GetPYIndexChar函数,... 我需要获取个edit中的text内容里的汉字首字母加在一起组成一个编码赋值给另外一个edit
在网上查询过之前的获取方法,都是一个写出来的GetPYIndexChar函数,用过以后,函数执行时报错,错误主体是'access violation at address 004c4699 in module 'project1.exe',Read of address 00000000. process stopped.
到底是为什么报的错呢?是因为缺少了什么字库还是什么原因呢?
这个函数应该如何写?是否需要汉字字库?
新的问题出来了!经过尝试,书中的源代码是可以直接实现取首字母的功能,最多是有写汉字无法识别,但是我将取首字母的函数考到自己写的代码中用时却会报下面的错误,这是为什么呢?access violation at address 004c4699 in module 'project1.exe',Read of address 00000000. process stopped!
报错时程序停止在‘case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of’
不知道WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) 这段代码执行出来的结果是个什么样的呢?有哪位达人有比较全的取首字母的方法呢?很多字都无法取到,很纠结!
展开
 我来答
baithan
2011-06-11 · TA获得超过717个赞
知道小有建树答主
回答量:593
采纳率:0%
帮助的人:577万
展开全部
碰巧我有这么一个函数
有点长,,不过,绝对能用

const py: array[216..247] of string = (
{216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + 'QMBSGZSCYJSYYZPG' +
{216}'KBZGYCYWYKGKLJSW' + 'KPJQHYZWDDZLSGMR' + 'YPYWWCCKZNKYDG',
{217}'TTNJJEYKKZYTCJNM' + 'CYLQLYPYQFQRPZSL' + 'WBTGKJFYXJWZLTBN' +
{217}'CXJJJJZXDTTSQZYC' + 'DXXHGCKBPHFFSSYY' + 'BGMXLPBYLLLHLX',
{218}'SPZMYJHSOJNGHDZQ' + 'YKLGJHXGQZHXQGKE' + 'ZZWYSCSCJXYEYXAD' +
{218}'ZPMDSSMZJZQJYZCD' + 'JEWQJBDZBXGZNZCP' + 'WHKXHQKMWFBPBY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KYXZ' + 'KHHGFLBCSMDLDG',
{244}'DZDBLZYYCXNNCSYB' + 'ZBFGLZZXSWMSCCMQ' + 'NJQSBDQSJTXXMBLT' +
{244}'XZCLZSHZCXRQJGJY' + 'LXZFJPHYXZQQYDFQ' + 'JJLZZNZJCDGZYG',
{245}'CTXMZYSCTLKPHTXH' + 'TLBJXJLXSCDQXCBB' + 'TJFQZFSLTJBTKQBX' +
{245}'XJJLJCHCZDBZJDCZ' + 'JDCPRNPQCJPFCZLC' + 'LZXBDMXMPHJSGZ',
{246}'GSZZQLYLWTJPFSYA' + 'SMCJBTZYYCWMYTCS' + 'JJLQCQLWZMALBXYF' +
{246}'BPNLSFHTGJWEJJXX' + 'GLLJSTGSHJQLZFKC' + 'GNNDSZFDEQFHBS',
{247}'AQTGYLBXMMYGSZLD' + 'YDQMJJRGBJTKGDHG' + 'KBLQKBDMBYLXWCXY' +
{247}'TTYBKMRTJZXQJBHL' + 'MHMJJZMQASLDCYXY' + 'QDLQCAFYWYXQHZ'
);

function ChnPy(Value: array of char): Char;
begin
Result := #0;
case Byte(Value[0]) of
176:
case Byte(Value[1]) of
161..196: Result := 'A';
197..254: Result := 'B';
end; {case}
177:
Result := 'B';
178:
case Byte(Value[1]) of
161..192: Result := 'B';
193..205: Result := 'C';
206: Result := 'S'; //参
207..254: Result := 'C';
end; {case}
179:
Result := 'C';
180:
case Byte(Value[1]) of
161..237: Result := 'C';
238..254: Result := 'D';
end; {case}
181:
Result := 'D';
182:
case Byte(Value[1]) of
161..233: Result := 'D';
234..254: Result := 'E';
end; {case}
183:
case Byte(Value[1]) of
161: Result := 'E';
162..254: Result := 'F';
end; {case}
184:
case Byte(Value[1]) of
161..192: Result := 'F';
193..254: Result := 'G';
end; {case}
185:
case Byte(Value[1]) of
161..253: Result := 'G';
254: Result := 'H';
end; {case}
186:
Result := 'H';
187:
case Byte(Value[1]) of
161..246: Result := 'H';
247..254: Result := 'J';
end; {case}
188..190:
Result := 'J';
191:
case Byte(Value[1]) of
161..165: Result := 'J';
166..254: Result := 'K';
end; {case}
192:
case Byte(Value[1]) of
161..171: Result := 'K';
172..254: Result := 'L';
end; {case}
193:
Result := 'L';
194:
case Byte(Value[1]) of
161..231: Result := 'L';
232..254: Result := 'M';
end; {case}
195:
Result := 'M';
196:
case Byte(Value[1]) of
161..194: Result := 'M';
195..254: Result := 'N';
end; {case}
197:
case Byte(Value[1]) of
161..181: Result := 'N';
182..189: Result := 'O';
190..254: Result := 'P';
end; {case}
198:
case Byte(Value[1]) of
161..217: Result := 'P';
218..254: Result := 'Q';
end; {case}
199:
Result := 'Q';
200:
case Byte(Value[1]) of
161..186: Result := 'Q';
187..245: Result := 'R';
246..254: Result := 'S';
end; {case}
201..202:
Result := 'S';
203:
case Byte(Value[1]) of
161..249: Result := 'S';
250..254: Result := 'T';
end; {case}
204:
Result := 'T';
205:
case Byte(Value[1]) of
161..217: Result := 'T';
218..254: Result := 'W';
end; {case}
206:
case Byte(Value[1]) of
161..243: Result := 'W';
244..254: Result := 'X';
end; {case}
207..208:
Result := 'X';
209:
case Byte(Value[1]) of
161..184: Result := 'X';
185..254: Result := 'Y';
end; {case}
210..211:
Result := 'Y';
212:
case Byte(Value[1]) of
161..208: Result := 'Y';
209..254: Result := 'Z';
end; {case}
213..215:
Result := 'Z';
216..247:
Result := py[Byte(Value[0])][Byte(Value[1]) - 160];
end; {case}
end;

function TitemMag.ChnToPY(Value: string): string;
var
I, L: Integer;
C: array[0..1] of char;
R: Char;
begin
Result := '';
L := Length(Value);
I := 1;
while I <= (L - 1) do
begin
if Value[I] < #160 then
begin
Result := Result + Value[I];
Inc(I);
end
else
begin
C[0] := Value[I];
C[1] := Value[I + 1];
R := ChnPY(C);
if r <> #0 then
Result := Result + R;
Inc(I, 2);
end;
end;
if I = L then
Result := Result + Value[L];
end;
追问
我的哥哥哎,这不是一点点长啊!往文本里面一放一看,8KB。鞠躬!先谢谢了!
可以说说这个函数的代码执行机制吗?我希望自己能完全读懂这些代码!
追答
e..其实我也没怎么详细看这个函数。。。我也是在网上找的。。。哈哈哈
pabc53
2011-06-18 · 超过11用户采纳过TA的回答
知道答主
回答量:58
采纳率:0%
帮助的人:27.1万
展开全部
你可能是调用了一个无效的参数
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
hhuayuan
2011-06-13 · 超过10用户采纳过TA的回答
知道答主
回答量:88
采纳率:0%
帮助的人:36.7万
展开全部
{以下代码在Delphi7中测试通过 可直接复制使用
用法:
procedure TForm1.btn1Click(Sender: TObject);
begin
Caption:= GetPy('金财税客户管理系统');
end;
}
function THBase.HexToInt(const HexValue: String): Integer;
begin
Val('$' + HexValue, Result, Result);
end;

function GetPy(const HZ: string): string;
var
HZ_bm1, HZ_bm2, I: Integer;
int_char, tem_char, retu_char: string;
uni_char: widestring;
int_hex, cou: Integer;
begin
uni_char := HZ; // ansi转换到 unicode 便于取字符串的个数汉字和英文宽度一致
cou := length(uni_char);
for I := 1 to cou do
begin
tem_char := uni_char[I]; // 宽字符取一个字在赋值到ansi 以便取gb2312字符
if length(tem_char) = 2 then
begin
HZ_bm1 := ord(tem_char[1]); // ansi字符取高位和低位的整数
HZ_bm2 := ord(tem_char[2]);
int_char := IntToHex(HZ_bm1, 2) + IntToHex(HZ_bm2, 2); // 直接利用字符合并成16进制整数
int_hex := HexToInt(int_char); // 在把16进制字符转换成整数

case int_hex of
$B0A1 .. $B0C4:
retu_char := 'A';
$B0C5 .. $B2C0:
retu_char := 'B';
$B2C1 .. $B4ED:
retu_char := 'C';
$B4EE .. $B6E9:
retu_char := 'D';
$B6EA .. $B7A1:
retu_char := 'E';
$B7A2 .. $B8C0:
retu_char := 'F';
$B8C1 .. $B9FD:
retu_char := 'G';
$B9FE .. $BBF6:
retu_char := 'H';
$BBF7 .. $BFA5:
retu_char := 'J';
$BFA6 .. $C0AB:
retu_char := 'K';
$C0AC .. $C2E7:
retu_char := 'L';
$C2E8 .. $C4C2:
retu_char := 'M';
$C4C3 .. $C5B5:
retu_char := 'N';
$C5B6 .. $C5BD:
retu_char := 'O';
$C5BE .. $C6D9:
retu_char := 'P';
$C6DA .. $C8BA:
retu_char := 'Q';
$C8BB .. $C8F5:
retu_char := 'R';
$C8F6 .. $CBF9:
retu_char := 'S';
$CBFA .. $CDD9:
retu_char := 'T';
$CDDA .. $CEF3:
retu_char := 'W';
$CEF4 .. $D188:
retu_char := 'X';
$D1B9 .. $D4D0:
retu_char := 'Y';
$D4D1 .. $D7F9:
retu_char := 'Z';
else
retu_char := Char(0);
end;
end
else
begin
retu_char := UpperCase(tem_char);
end;
Result := Result + retu_char;
end;
end;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式