使用POS进行判断! 或者for 0 to length() do if string[x]='e' then
截获输入消息用strpos(edit1.text,'e')<>nil来判断。
不好意思,应该是strpos(pchar(edit1.text),'e')<>nil才对。
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);begin if (key not in ['0'..'9']) then //if the input is a character begin if pos(key,edit1.Text)>0 then //do something you would end; end;
可以if Trim(Edit.Text)='' then if key='e' or key='E' then Key:=#0;
"必须且只能拥有一个E,且E不能放在第一个字符!" "即如果e不在第一个位置的话,输入了一个e后,就不能输入第二个e了" 你还是没说清楚,这两句话的意思就不一样。 我还是不清楚你到底要求什么,看看下面这段话符不符合你的要求, procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (trim(edit1.Text)='') and (key in ['e','E']) then key:=#0 else if ((pos('e',edit1.Text)>0) or (pos('E',edit1.Text)>0)) and (key in ['e','E']) then key:=#0; end;
或者写成这样更简练些 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key in ['e','E'] then if (trim(edit1.Text)='') then key:=#0 else if (pos('e',edit1.Text)>0) or (pos('E',edit1.Text)>0) then key:=#0; end;
或者for 0 to length() do
if string[x]='e' then
if (key not in ['0'..'9']) then //if the input is a character
begin
if pos(key,edit1.Text)>0 then //do something you would
end;
end;
in not (key in ['0'..'9']) then
可以在edit的onChange事件中用循环进行e的个数的统计。
begin
if (key='e') and (pos('e',edit1.text) >0) then
key:=#0
end;
if not ( key in ['0'..'9'] ) then
if ( key = 'e' ) and ( pos('e',edit1.text > 0 ) then
key := #0
POS('e',str)>0 表示同样的意思,我就奇怪你为什么要用POS('e',str)=1来判断。
屏蔽Ctrl+V
屏蔽右键菜单的 粘贴
屏蔽替换 比如 现在有 adefg 并且,d字符高亮显示,可能可以用e替换d
需要进行消息拦截
哈,本人不会
就象只能输入Double类型的串一样
POS('e',str)=1 这样写的目的我是可以控制第一个不能为e
if key='e' or key='E' then
Key:=#0;
"即如果e不在第一个位置的话,输入了一个e后,就不能输入第二个e了"
你还是没说清楚,这两句话的意思就不一样。
我还是不清楚你到底要求什么,看看下面这段话符不符合你的要求,
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (trim(edit1.Text)='') and (key in ['e','E']) then
key:=#0
else
if ((pos('e',edit1.Text)>0) or (pos('E',edit1.Text)>0)) and (key in ['e','E']) then
key:=#0;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key in ['e','E'] then
if (trim(edit1.Text)='') then
key:=#0
else
if (pos('e',edit1.Text)>0) or (pos('E',edit1.Text)>0) then
key:=#0;
end;