procedure TForm1.Edit1Change(Sender: TObject);
const
MaxCharCount=5; // 限制编辑框内只能输入5个字符
var
i,c:integer;
s:string;
begin
if Edit1.Tag=0 then
begin
i:=1;
c:=0;
s:='';
While (c<MaxCharCount) and (i<=Length(Edit1.Text)) do
begin
case ByteType(Edit1.Text,i) of
mbSingleByte:
begin
s:=s+Edit1.Text;
inc(i)
end;
mbLeadByte:
begin
s:=s+Edit1.Text+Edit1.Text[i+1];
i:=i+2
end
else
begin
inc(i);
Continue
end
end;
inc(c)
end;
Edit1.Tag:=1;
Edit1.Text:=s
end
else
Edit1.Tag:=0
end;