D
delphilai
Unregistered / Unconfirmed
GUEST, unregistred user!
第一次写控件,不知道如何写?
写一个继承自Edit编辑框的控件,要求该编辑框只能接收数字或“.”,如何重载DoKeydown事件?
不能用override一个静态的DokeyDown事件。
unit EditDigit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TEditDigit = class(TEdit)
private
{ Private declarations }
protected
{ Protected declarations }
OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TEditDigit]);
end;
procedure OnkeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
inherited;
if not (Key in ['0'..'9']) then
key:=0;
end;
end.
具体怎么实现?
写一个继承自Edit编辑框的控件,要求该编辑框只能接收数字或“.”,如何重载DoKeydown事件?
不能用override一个静态的DokeyDown事件。
unit EditDigit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TEditDigit = class(TEdit)
private
{ Private declarations }
protected
{ Protected declarations }
OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TEditDigit]);
end;
procedure OnkeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
inherited;
if not (Key in ['0'..'9']) then
key:=0;
end;
end.
具体怎么实现?