我有如下代码,我想将我的控件拥有ONKEYPRESS 、
ONEXIT 两个事件
但是我的代码总是不好市,这两个事件总是没有反映
代码如下,请各位帮小弟更正
unit labedit;
interface
uses
Windows, Messages, stdctrls,SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
tlabedit = class(twincontrol)
private
fedit:tedit;
flab:tlabel;
fexit:tnotifyevent;
fkey:TKeyPressEvent;
function getcaption: string;
function gettext: string;
procedure settext(const Value: string);
procedure setcaption(const Value: string);
procedure wmsize(var message:tmessage) ;message wm_size;
procedure cmfontchanged(var message :Tmessage);message CM_fontchanged;
protected
public
constructor create(aowner:tcomponent);override;
destructor destory;
published
property text:string read gettext write settext;
property caption :string read getcaption write setcaption;
property onexit read fexit write fexit;
property onkeypress read fkey write fkey;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('standard', [tlabedit]);
end;
{ tlabedit }
procedure tlabedit.cmfontchanged(var message: Tmessage);
begin
inherited;
end;
constructor tlabedit.create(aowner: tcomponent);
begin
inherited create(aowner);
width:=200;
height:=25;
flab:=tlabel.Create(self);
flab.Font.Name:='宋体';
flab.Font.Size:=12;
flab.Parent:=self;
flab.Left:=left;
flab.Width:=75;
flab.height:=25;
flab.Visible:=true;
fedit:=tedit.Create(self);
fedit.Parent:=self;
fedit.Left:=left+flab.Width+5;
fedit.Width:=width-5-flab.Width;
fedit.height:=25;
fedit.Font.Name:='宋体';
fedit.Font.Size:=10;
fedit.Visible:=true;
fedit.OnKeyPress:=fkey;
fedit.OnExit:=fexit;
end;
destructor tlabedit.destory;
begin
flab.free;
fedit.Free;
inherited;
end;
function tlabedit.getcaption: string;
begin
result:=flab.Caption;
end;
function tlabedit.gettext: string;
begin
result:=fedit.Text;
end;
procedure tlabedit.setcaption(const Value: string);
begin
flab.Caption:=value;
end;
procedure tlabedit.settext(const Value: string);
begin
fedit.Text:=value;
end;
procedure tlabedit.wmsize(var message: tmessage);
begin
inherited;
flab.height:=height;
fedit.Width:=height;
fedit.Width:=width-flab.Width-5;
end;
end.