把我自己的事件代替原有的事件(50分)

  • 主题发起人 主题发起人 shbjkl
  • 开始时间 开始时间
S

shbjkl

Unregistered / Unconfirmed
GUEST, unregistred user!
unit myedit;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
Tmyedit = class(TEdit)
private

{ Private declarations }

protected
{ Protected declarations }
public
{ Public declarations }
published
//constructor Create (AOwner: TComponent); override;
procedure KeyPress(Sender: TObject; var Key: Char);override;
{ Published declarations }
end;
//procedure Tmyflatedit1.Keypress(Sender:TObject; var Key:char);override;
procedure Register;

implementation

procedure KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not (key in['0'..'9',#46,#8,'.','-']) then
begin
key:=#0;
end;
end;
procedure Register;
begin
RegisterComponents('standard', [tmyedit]);
end;


end.
报错:Declaration of 'KeyPress' differs from previous declaration
 
implementation

procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);
--------
 
implementation

procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);
~~~~~~~~~
 
不是的
错误在procedure KeyPress(Sender: TObject; var Key: Char);override;
 
procedure tmyedit.KeyPress(Sender: TObject; var Key: Char);override;
报:undeclared inidentifier "tmyedit"
 
将其放在 public 中。
 
是的,你说得也没有错,
不过这个问题的解决方法就是上面两位说的
不信可以试一下
 
在public中呀,没有用
 
你的原先在published中!
 
不要override;吗
 
不行还是undeclared inidentifier "tmyedit"
 
faint..,怎么会?你再贴出来看一下。
 
unit myedit;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
tmyedit = class(TEdit)
private

{ Private declarations }

protected
{ Protected declarations }
public
procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);override;
{ Public declarations }
published
//constructor Create (AOwner: TComponent); override;

{ Published declarations }
end;
//procedure Tmyflatedit1.Keypress(Sender:TObject; var Key:char);override;
procedure Register;

implementation

procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not (key in['0'..'9',#46,#8,'.','-']) then
begin
key:=#0;
end;
end;
procedure Register;
begin
RegisterComponents('standard', [tmyedit]);
end;


end.
 
public
procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);override;

改成
public
procedure KeyPress(Sender: TObject; var Key: Char);override;
 
[Error] myedit.pas(17): Declaration of 'KeyPress' differs from previous declaration
 
呵呵,我服了。

protected
procedure KeyPress(Sender: TObject; var Key: Char);override;


implementation

procedure Tmyedit.KeyPress(Sender: TObject; var Key: Char);
~~~~~~~~~
 
问题依旧一样
 

procedure KeyPress(var Key: Char); override;//改为这个
 
多人接受答案了。
 
后退
顶部