如何判断子类是不是某类的子类?

一如当初 2011-12-04 10:09:34
比如有个父类A,有若干子类B,C等,如何判断类B,类C是从类A继承的?
...全文
258 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaikai_kk 2011-12-04
  • 打赏
  • 举报
回复
InheritsFrom()

如:
if Button1.InheritsFrom(TButton) then
showmessage('TButton是Button1的祖先');

if B.InheritsFrom(A) then
showmessage('A是B的祖先');
cntigercat 2011-12-04
  • 打赏
  • 举报
回复
Oraclers 2011-12-04
  • 打赏
  • 举报
回复
你看下面的代码就知道了,判断一个类的父类。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(Label1.ClassName);
showmessage(Label1.ClassParent.ClassName);
showmessage(Label1.ClassParent.ClassParent.ClassName);
end;

end.
山东蓝鸟贵薪 2011-12-04
  • 打赏
  • 举报
回复
帮你顶顶先
ccrun.com 2011-12-04
  • 打赏
  • 举报
回复
InheritsFrom依赖VCL体系吧。

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧