B
Baisir
Unregistered / Unconfirmed
GUEST, unregistred user!
帮忙解答另增高分。(在线急等)
一个继承edit的控件,我在change事件里加了一些东西,也能编译过。
但把控件放在窗体上时出现错误。错误信息如下:
Control 'edit_cs1' has no parent window.
但是我要是把change里的东西全部注释掉,既然能用,百思不得其解。
代码如下:
unit Edit_cs;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TEdit_cs = class(TEdit)
private
FaMaxnum:integer;
procedure setaMaxnum(const value:integer);
{ Private declarations }
protected
procedure change;override;
{ Protected declarations }
public
{ Public declarations }
published
property amaxnum:integer read Famaxnum write setaMaxnum;
{ Published declarations }
end;
procedure Register;
implementation
procedure TEdit_cs.setaMaxnum(const value:integer);
begin
Famaxnum:=value;
end;
procedure Register;
begin
RegisterComponents('BAI_new', [TEdit_cs]);
end;
procedure Tedit_cs.change;
var
i:integer;
b:integer;
label e;
begin
if self.Text ='' then
exit;
b:=0;
for i:=1 to self.amaxnum do
begin
if self.text=inttostr(i) then
begin
b:=1;
goto e;
end;
end;
e:
if b<>1 then
begin
self.Text:=copy(self.Text,1,length(self.Text)-1);
self.SetFocus ;
end;
end;
end.
一个继承edit的控件,我在change事件里加了一些东西,也能编译过。
但把控件放在窗体上时出现错误。错误信息如下:
Control 'edit_cs1' has no parent window.
但是我要是把change里的东西全部注释掉,既然能用,百思不得其解。
代码如下:
unit Edit_cs;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TEdit_cs = class(TEdit)
private
FaMaxnum:integer;
procedure setaMaxnum(const value:integer);
{ Private declarations }
protected
procedure change;override;
{ Protected declarations }
public
{ Public declarations }
published
property amaxnum:integer read Famaxnum write setaMaxnum;
{ Published declarations }
end;
procedure Register;
implementation
procedure TEdit_cs.setaMaxnum(const value:integer);
begin
Famaxnum:=value;
end;
procedure Register;
begin
RegisterComponents('BAI_new', [TEdit_cs]);
end;
procedure Tedit_cs.change;
var
i:integer;
b:integer;
label e;
begin
if self.Text ='' then
exit;
b:=0;
for i:=1 to self.amaxnum do
begin
if self.text=inttostr(i) then
begin
b:=1;
goto e;
end;
end;
e:
if b<>1 then
begin
self.Text:=copy(self.Text,1,length(self.Text)-1);
self.SetFocus ;
end;
end;
end.