Y
ynfly
Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个继承于Tpanel对象的控件,可以通过自己的方法addlabel增加一个Label,编译通过,
但在使用时通过Mypanel1.addlabel方法时出错,并且不能显示Label,请各位大哥帮忙,我只是一个
爱好Delphi编程的人而已,难的问题我就解决不了,谢谢各位了
代码如下:
unit MyPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,StdCtrls;
type
TMyPanel = class(TPanel)
private
lb:Tlabel;
{ Private declarations }
protected
{ Protected declarations }
public
procedure addLabel;
constructor create(Aowner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure TMypanel.addLabel ;
begin
if not assigned(lb) then
begin
lb.Create(self); //以本控件为容器创建lb
lb.Caption :='hello';
lb.Left :=10;
lb.Top:=10;
lb.Invalidate ;
end;
end;
constructor tMypanel.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
end;
destructor tMypanel.destroy ;
begin
if Assigned(lb) then
lb.free;
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('ActiveX', [TMyPanel]);
end;
end.
但在使用时通过Mypanel1.addlabel方法时出错,并且不能显示Label,请各位大哥帮忙,我只是一个
爱好Delphi编程的人而已,难的问题我就解决不了,谢谢各位了
代码如下:
unit MyPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,StdCtrls;
type
TMyPanel = class(TPanel)
private
lb:Tlabel;
{ Private declarations }
protected
{ Protected declarations }
public
procedure addLabel;
constructor create(Aowner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure TMypanel.addLabel ;
begin
if not assigned(lb) then
begin
lb.Create(self); //以本控件为容器创建lb
lb.Caption :='hello';
lb.Left :=10;
lb.Top:=10;
lb.Invalidate ;
end;
end;
constructor tMypanel.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
end;
destructor tMypanel.destroy ;
begin
if Assigned(lb) then
lb.free;
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('ActiveX', [TMyPanel]);
end;
end.