有个EDIT控件,假如它的TEXT是‘123456789’
我现在想实现的,让这个控件的部分只读,意思就是前面123是只读的,必须保证前面是开头是123。这样的代码好象不可以的:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
s: string;
begin
s := '123';
if (length(edit1.Text) = 3) or (copy(edit1.text, 1, 3) <> s) then
Key := #0;end;
请大虾帮忙,分不够再加
我现在想实现的,让这个控件的部分只读,意思就是前面123是只读的,必须保证前面是开头是123。这样的代码好象不可以的:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
s: string;
begin
s := '123';
if (length(edit1.Text) = 3) or (copy(edit1.text, 1, 3) <> s) then
Key := #0;end;
请大虾帮忙,分不够再加
解决方案 »
- 串口通信,鸭梨很大。电子秤问题。。
- 请教IdHttp如何设置cookies信息?
- 如何对数据库中的文件操作,在线等!!!
- 请JetJack (喷气引擎) 帮忙。。。!!!
- 菜鸟问一个关于端口的问题!
- [microsoft][odbc microsoft access]参数不足,期待是1
- 关于文件操作的问题
- 关于Tstringgrid的行颜色改变的问题??
- 关于treeview的两个问题。
- 关于IE Twebbrowser的问题??
- 怎么让 TStringList 变量指向一个空(nil)?
- /***************在串口通信中如何设置RTS信号?*******************/
s: string;
begin
s := '123';
if (copy(edit1.text, 1, 3) = s) then
if (length(edit1.text) <= 3) and (key = #8)then
Key := #0;
end;
var
s: string;
strAftChg:string;
begin
s := '123';
if edit1.SelStart<2 then
begin
key:=#0;
exit;
end;
strAftChg:=Copy(edit1.Text,1,edit1.SelStart) + Key;
if (edit1.SelStart<length(edit1.Text)) and ((edit1.SelLength+ edit1.SelStart)<length(edit1.Text)) then
strAftChg:=StrAftChg+ copy(edit1.Text,edit1.SelLength+ edit1.SelStart+1, length(edit1.Text)- edit1.SelLength- edit1.SelStart);
if (copy(strAftChg, 1, 3) <> s) then
Key := #0;end;
这段代码作了模拟修改后处理用strAftChg来判断,而不是edit.text