unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Edit1: TEdit;
Function OnlyInsNum(Sender: TObject; Key: Char; CanInsNeg: Boolean): Char;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
Function TForm1.OnlyInsNum(Sender: TObject; Key: Char; CanInsNeg: Boolean): Char;
begin {*****限制只输入数字,不能输入两个小数点*****}
if not (Sender is TEdit) then
begin
Result := #0;
Exit; //不是TEdit直接退出
end;
if not (Key in ['0'..'9','.', #27{ESC}, #8{退格}, #13{回车}]) then
begin
if (CanInsNeg) and (Key = '-')then //如果可以输入负数,并且输入的是负数则返回
Result := Key
else Result := #0;
end
else if (Key = '.') and (Pos('.', (Sender as TEdit).Text) <> 0) then //位小数点,且已经存在小数点了
begin
Result := #0; //返回不能输入
end
else
begin
Result := Key;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
Key := form1.OnlyInsNum(Sender, Key);//提示Not enough actual parameters
end; end.
提示Not enough actual parameters?
请指点下,谢谢
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Edit1: TEdit;
Function OnlyInsNum(Sender: TObject; Key: Char; CanInsNeg: Boolean): Char;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
Function TForm1.OnlyInsNum(Sender: TObject; Key: Char; CanInsNeg: Boolean): Char;
begin {*****限制只输入数字,不能输入两个小数点*****}
if not (Sender is TEdit) then
begin
Result := #0;
Exit; //不是TEdit直接退出
end;
if not (Key in ['0'..'9','.', #27{ESC}, #8{退格}, #13{回车}]) then
begin
if (CanInsNeg) and (Key = '-')then //如果可以输入负数,并且输入的是负数则返回
Result := Key
else Result := #0;
end
else if (Key = '.') and (Pos('.', (Sender as TEdit).Text) <> 0) then //位小数点,且已经存在小数点了
begin
Result := #0; //返回不能输入
end
else
begin
Result := Key;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
Key := form1.OnlyInsNum(Sender, Key);//提示Not enough actual parameters
end; end.
提示Not enough actual parameters?
请指点下,谢谢
CanInsNeg没传参
不改什么,加了个true就不提示出错是怎么回事