D
desertsmoke
Unregistered / Unconfirmed
GUEST, unregistred user!
程序中动态创建控件,如一中所示。自己做了两个控件:TRJ和TNewRJ,TNewRJ是从
TRJ派生来的,只是在TRJ的基础上加了一个标签TLabel,在接口部分的Uses中引用RJ
后动态创建控件一切正常,但是引用NewRJ后,就会产生错误,如下:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EClassNotFound with message
'Class TLabel not found'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
也就是说FindClass('TLabel')失败!
哪位大虾知道这是怎么回事,怎么引起的,如何解决?
------------------------------------------------------------------------------
一、动态创建控件单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ROUNDLED, buttons, ComCtrls, DB, DBClient,
MConnect, SConnect, RJ, NewRJ;
const
TCClass :Array[1..3] of TPersistentClass=(TImage, TLabel, TShape);
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
NewControl:TObject;
begin
NewControl:= (TComponentClass(FindClass('TLabel'))).Create(Self);//这句失败!!!
(NewControl as Tlabel).Parent := self;
NewControl:= (TComponentClass(FindClass('TRJ'))).Create(Self);
(NewControl as TRJ).Parent := self;
......
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterClasses(TCClass); //可能这里就是失败的!
end;
end.
********************************************************************
二、控件单元
unit NewRJ;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, RJ, QStdCtrls,
Graphics, Forms, Dialogs, stdctrls;
type
TLabelPosition = (lpAbove, lpBelow);
TNewRJ = class(TRJ)
ShowLabel:TLabel;
private
{ Private declarations }
......
************************************
注:解决并说明问题者单独给200分。
TRJ派生来的,只是在TRJ的基础上加了一个标签TLabel,在接口部分的Uses中引用RJ
后动态创建控件一切正常,但是引用NewRJ后,就会产生错误,如下:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EClassNotFound with message
'Class TLabel not found'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
也就是说FindClass('TLabel')失败!
哪位大虾知道这是怎么回事,怎么引起的,如何解决?
------------------------------------------------------------------------------
一、动态创建控件单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ROUNDLED, buttons, ComCtrls, DB, DBClient,
MConnect, SConnect, RJ, NewRJ;
const
TCClass :Array[1..3] of TPersistentClass=(TImage, TLabel, TShape);
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
NewControl:TObject;
begin
NewControl:= (TComponentClass(FindClass('TLabel'))).Create(Self);//这句失败!!!
(NewControl as Tlabel).Parent := self;
NewControl:= (TComponentClass(FindClass('TRJ'))).Create(Self);
(NewControl as TRJ).Parent := self;
......
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterClasses(TCClass); //可能这里就是失败的!
end;
end.
********************************************************************
二、控件单元
unit NewRJ;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, RJ, QStdCtrls,
Graphics, Forms, Dialogs, stdctrls;
type
TLabelPosition = (lpAbove, lpBelow);
TNewRJ = class(TRJ)
ShowLabel:TLabel;
private
{ Private declarations }
......
************************************
注:解决并说明问题者单独给200分。