大
大花鸡
Unregistered / Unconfirmed
GUEST, unregistred user!
type
TParents = class(TWinControl)
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
virtual
abstract;
end;
TChild1 = class(TParents)
private
SS: String;
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
override;
end;
TChild2 = class(TParents)
private
SS: String;
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
override;
end;
。。。。。。
{ TParents }
constructor TParents.create(AOwner: TComponent);
begin
inherited;
end;
destructor TParents.destroy;
begin
inherited;
end;
{ TChild2 }
procedure TChild2.add(S: String);
begin
inherited;
showmessage('TChild2.add ' + S);
if Self.Owner = nil then
showmessage('NIL')
else
showmessage(Owner.Name);
end;
constructor TChild2.create(AOwner: TComponent);
begin
inherited;
ss := 'asfd';
end;
destructor TChild2.destroy;
begin
inherited;
end;
{ TChild1 }
procedure TChild1.add(S: String);
begin
inherited;
showmessage('TChild2.add ' + S);
if Self.Owner = nil then
showmessage('NIL')
else
showmessage(Owner.Name);
end;
constructor TChild1.create(AOwner: TComponent);
begin
inherited;
ss := 'asfd';
end;
destructor TChild1.destroy;
begin
inherited;
end;
initialization
RegisterClasses([TChild2, TChild1]);
finalization
UnRegisterClass(TChild2);
UnRegisterClass(TChild1);
使用:
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
cc: TParents;
begin
s := 'TChild' + Edit2.Text;
CC :=(FindClass(S).Create as TParents);
CC.Parent := form1;
CC.add(Edit1.Text);
CC.Free;
end;
这样是可以创建TChildX的实例,可是没有handle,也没法设Parent。怎么 解决这个问题?
TParents = class(TWinControl)
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
virtual
abstract;
end;
TChild1 = class(TParents)
private
SS: String;
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
override;
end;
TChild2 = class(TParents)
private
SS: String;
public
constructor create(AOwner: TComponent)
override;
destructor destroy
override;
procedure add(S: String)
override;
end;
。。。。。。
{ TParents }
constructor TParents.create(AOwner: TComponent);
begin
inherited;
end;
destructor TParents.destroy;
begin
inherited;
end;
{ TChild2 }
procedure TChild2.add(S: String);
begin
inherited;
showmessage('TChild2.add ' + S);
if Self.Owner = nil then
showmessage('NIL')
else
showmessage(Owner.Name);
end;
constructor TChild2.create(AOwner: TComponent);
begin
inherited;
ss := 'asfd';
end;
destructor TChild2.destroy;
begin
inherited;
end;
{ TChild1 }
procedure TChild1.add(S: String);
begin
inherited;
showmessage('TChild2.add ' + S);
if Self.Owner = nil then
showmessage('NIL')
else
showmessage(Owner.Name);
end;
constructor TChild1.create(AOwner: TComponent);
begin
inherited;
ss := 'asfd';
end;
destructor TChild1.destroy;
begin
inherited;
end;
initialization
RegisterClasses([TChild2, TChild1]);
finalization
UnRegisterClass(TChild2);
UnRegisterClass(TChild1);
使用:
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
cc: TParents;
begin
s := 'TChild' + Edit2.Text;
CC :=(FindClass(S).Create as TParents);
CC.Parent := form1;
CC.add(Edit1.Text);
CC.Free;
end;
这样是可以创建TChildX的实例,可是没有handle,也没法设Parent。怎么 解决这个问题?