怪了,edit的onexit (100分)

  • 主题发起人 主题发起人 wjqdelphi
  • 开始时间 开始时间
W

wjqdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
我自己作的一共Edit控件:
unit DimEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Forms,Dialogs,Graphics;
Type
TDimStyle=(horizontal,vertical);
type
TDimEdit = class(TEdit)
private
FCanInPut: boolean;
procedure SetCanInPut(const Value: boolean);
{ Private declarations }
protected
procedure Click; override;
procedure keypress(var Key: Char);override;
procedure KeyDown(var Key: Word; Shift: TShiftState);override;
procedure DoExit;override;
{ Protected declarations }
public
{ Public declarations }
constructor NewCreate(Aowner: TComponent);
published
property CanInPut:boolean read FCanInPut write SetCanInPut;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DimEdit', [TDimEdit]);
end;
{ TDimEdit }
constructor TDimEdit.NewCreate(Aowner: TComponent);
begin
inherited create(Aowner);
CanInPut:= False;
BorderStyle:= bsnone ;
Color:= clwhite;
Width:= 30;
Height:= 15;
BorderWidth:=0;
end;
procedure TDimEdit.SetCanInPut(const Value: boolean);
begin
FCanInPut := Value;
end;
procedure TDimEdit.Click;
begin
inherited;
CanInPut:= True;
SelectAll;
Height:= 18;
sendmessage(getfocus, WM_SETFOCUS, 0, 0);
end;
procedure TDimEdit.keypress(var Key: Char);
begin
inherited;
if Not( CanInPut and (key in ['0'..'9',#8])) then
begin
key := #0;
exit;
end;
end;
procedure TDimEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
if Key= 13 then
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 15;
sendmessage(getfocus, WM_KILLFOCUS, 0, 0);
end;
end;

procedure TDimEdit.DoExit;
begin
inherited;
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
procedure TDimEdit.DimExit(Sender: TObject);
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
动态创建时,点击它时总会不断触发onexit,哪的问题?
 
procedure TDimEdit.DimExit(Sender: TObject);
begin
BorderStyle:= bsNone;
CanInPut:= False;
Height:= 18;
end;
没有声名;
这是去掉后试的,没事呀
private
procedure MyExit(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
DE:array [0..3]of TDimEdit;
I:Integer;
begin
for I:=0 to 3 do
begin
DE:=TDimEdit.Create(Self);
DE.Top:=I*20;
DE.Left:=I*30;
DE.Parent:=Form1;
DE.OnExit:=MyExit;
end;
end;

procedure TForm1.MyExit(Sender: TObject);
begin
ShowMessage('asdf');
end;

不像你说的那样点击时不断触发OnExit呀
 
我也搞不懂了,有时行(单独测试),有时不行(在我的程序中),点击它后先触发dimexit;
然后dimclick,这时就不断调用,cpu使用率持续百分之百

那我的procedure DoExit;override;是重载了TEdit的onexit事件吗?
 
我曾遇到过类似的问题
你应该这样子声明:
procedure WmSetFocus(var msg:Tmessage);message Wm_SetFocus;

procedure Edit.WmSetFocus(var msg:Tmessage);
begin
//To Do 自己的程序
inherited;
end;
这样子就可以解决了。试试看!
 
多人接受答案了。
 
后退
顶部