//第一个问题:为什么在Delphi2009的环境下会出错呢。
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) then
Key := Chr(0);
end;
//第二个问题:为什么Delphi2009的编译器回车后不能换行呢,比如粘贴代码后想再编辑,
//回车后不能换行,只是光标移动而已.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) then
Key := Chr(0);
end;
//第二个问题:为什么Delphi2009的编译器回车后不能换行呢,比如粘贴代码后想再编辑,
//回车后不能换行,只是光标移动而已.
第二个可能是用D版的原因,关闭delphi重新打开即可,我用D版的D7也经常出现此问题~~
[DCC Error] Unit1.pas(26): E2003 Undeclared identifier: 'Edit1KeyPress'
[DCC Error] Unit1.pas(26): E2029 ';' expected but '(' found
[DCC Error] Unit1.pas(26): E2029 ';' expected but ')' found
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
晕死!刚装的时候回车换行不会这样,倒是按Ctrl+V粘贴代码就会出现一个小符号。
还以为IDE不支持,晕。现在无缘无故好了。就不能回车换行。
PS:微软的开发工具中盗版的都很好用很正常啊。
begin
if CharInset(key,['0'..'9']) then showMessage('ok');end;
(Key in ['0'..'9'])出错是因为D2009里Char是Unicode字符了,而集合只能用于一个字节的有序类型的。所以出错。用('0'<=Key) and (Key<='9')来解决就好了。
procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if CharInset(key,['0'..'9']) then key := char(#0);end;
//回车后不能换行,只是光标移动而已.
按下你鍵盤的“Insert" 鍵後再試。
procedure Edit1KeyPress(Sender: TObject; var Key: Char); 如果没有加上即可~~
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) then
Key := Chr(0);
end;end.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) then
Key := Chr(0);
end;
2.edit组件没发现有能换行的,换行一般使用memo组件或rich组件。
哥们,这个还是提示出错。[DCC Error] Unit1.pas(25): E2003 Undeclared identifier: 'Edit1KeyPress'
[DCC Error] Unit1.pas(25): E2029 ';' expected but '(' found
[DCC Error] Unit1.pas(25): E2029 ';' expected but ')' found
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'