Delphi运行的时候,怎样用一个已经弄的的TForm作为模版,新创建的TForm对象可以继承它?

LoveDana 2002-08-21 07:27:10
也就是说,怎样继承一个自己的窗体/对象?
...全文
106 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
calixinlin 2002-08-22
  • 打赏
  • 举报
回复
打开你包含Form1的工程,比如工程名为MyProject,选择菜单
File->New->Other->MyProject->
选择要继承的Form1,同时选中下面的Inherit旁边的RadioButton
rainsea 2002-08-22
  • 打赏
  • 举报
回复
用模板是不错的选择,同时也符合对象设计思想。在你的Form上点右键,在弹出的菜单里选Add to Repository,就把它加到模板里面了。想用模板的话,菜单Tools | Repository,在里面找到你想要的模板
哇宁 2002-08-22
  • 打赏
  • 举报
回复
将Unit加入工程
打开file->new->other->projectname->
点你要继承的form

或新建一个FORM,将其改为

type
TForm2 = class(TForm1)
renzhm 2002-08-22
  • 打赏
  • 举报
回复
现在在工程的运行中,已经有Form1,我怎样把Form2继承Form1?

1、将
type
TFrm2 = class(TFrm)//TFrm为你的父类窗体

2、打开form2的窗体文件.dfm

修改:Object 为inherited

再把
Color = 14215660
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
这样有继承类型的语句删掉
------------------------------------------------
注意一点:若子窗体和父窗体有重名控件,你最好提前更名!

祝你好运!
delphi0302 2002-08-22
  • 打赏
  • 举报
回复
o include an object from the Object Repository, you can:

Copy the item.
Inherit from the item.
Use the item directly.

Copying Items

When you copy an item, you make an exact duplicate of the item and add it to your project if it is a form or data module. Any changes to the item in the Object Repository will not be reflected in your copy. Alterations you make to your copy will not affect the original Repository item.

Note: Copying is the only option available for using project templates or project wizards. Using a wizard does not add shared code; it runs a process that generates its own code.

Inheriting Items

Inheriting items is the most flexible and powerful way to use a Repository object. Inheriting lets you reuse items within the same project.

When you inherit an item, a new class is derived from the item and is added to your project. When you recompile your project, any changes made to the item in the Object Repository are reflected in your derived class, unless you have changed a particular aspect.

Changes made to your derived class do not affect the shared item in the Object Repository.

Note: You can inherit forms, dialog boxes, and data modules but not project templates. This is the only option available for reusing items from within the same project.

Using Items Directly

You use the Using Items Directly option primarily with data modules. When you use an item directly, the item is added to your project as if you had created it as part of the project. Design-time changes made to the item appear in all projects that directly use the item as well as any projects that inherit from the item.

Note: Using Items Directly is an option for forms, dialog boxes, and data modules. Modify these items only at runtime to avoid making changes that affect other modules.
delphi0302 2002-08-22
  • 打赏
  • 举报
回复
现在在工程的运行中,已经有Form1,我怎样把Form2继承Form1?

file->new->other->project1->
点你的form1
同时选中下面的Inherit旁边的RadioButton

1 inherit 生成的form2继承form1,form1是form2的父类
2 use 生成的form2应用form1,当修改form2的属性时form1也会改变
3copy 我记得不太清楚了问问别人吧
hfycl 2002-08-21
  • 打赏
  • 举报
回复
form2 = class(form1)
LoveDana 2002-08-21
  • 打赏
  • 举报
回复
现在在工程的运行中,已经有Form1,我怎样把Form2继承Form1?
LoveDana 2002-08-21
  • 打赏
  • 举报
回复
to:delphi0302(好好学习,天天向上!)

可以详细说说怎样Inherit么?或者给个具体例子更好,我额外给你100分,如何?
windofsun 2002-08-21
  • 打赏
  • 举报
回复
还可以用模板(或称之为“仓库”)。在你的Form上点右键,在弹出的菜单里选Add to Repository,就把它加到模板里面了。想用模板的话,菜单Tools | Repository,在里面找到你想要的模板
windofsun 2002-08-21
  • 打赏
  • 举报
回复
如果只是在同一个dpr中(假设叫Project1.dpr),可以这样:先新建一个Form,假设叫Form1,你在上面放你需要加的控件,然后选菜单New | Other...,在其中的Project1选项页里面可以看到Form1。选中它,点击OK
delphi0302 2002-08-21
  • 打赏
  • 举报
回复
如果这个窗体加在了你的程序中
file->new->other->projectname->
点你的form

如果继承就用inherit
LoveDana 2002-08-21
  • 打赏
  • 举报
回复
楼上,可以详细一点么?可以给出应用的例子吗?


pekiee 2002-08-21
  • 打赏
  • 举报
回复
TForm1=class(TForm)

TForm2=class(TForm1)

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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