我要写一个delphi 按回车就能跳转到url的Tedit的控件,具体代码怎么写?
[Error]MyEdit.pas(14):Declarationof'KeyPress'differsfrompreviousdeclarationtypeTMyEdi...
[Error] MyEdit.pas(14): Declaration of 'KeyPress' differs from previous declaration
type
TMyEdit = class(TEdit)
private
FUrl : AnsiString;
{ Private declarations }
protected
procedure KeyPress;override; //第14行
{ Protected declarations }
public
constructor create(Aowner : TComponent);override;
{ Public declarations }
published
property Url: AnsiString read Furl write Furl;
{ Published declarations }
end; 展开
type
TMyEdit = class(TEdit)
private
FUrl : AnsiString;
{ Private declarations }
protected
procedure KeyPress;override; //第14行
{ Protected declarations }
public
constructor create(Aowner : TComponent);override;
{ Public declarations }
published
property Url: AnsiString read Furl write Furl;
{ Published declarations }
end; 展开
展开全部
procedure KeyPress;override;
这个override说明你希望继承父类或祖先类的方法,但是父类或者祖先类的KeyPresss方法的参数不是这样的,所以报错了。
继承这个方法是正确的做法,这样可以实现你的需求。你在代码中判断当按下回车键时自动跳转到指定URL即可。
protected
procedure KeyPress(var Key: Char); override;
......
procedure TMyEdit.KeyPress(var Key: Char);
begin
inherited;
if Key = #13 then
begin
Key := #0;
// OpenUrl(Furl);
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询