关于对DataModule使用继承发生的问题(奇怪到无语)(300分)

  • 主题发起人 主题发起人 blue_morning
  • 开始时间 开始时间
B

blue_morning

Unregistered / Unconfirmed
GUEST, unregistred user!
1、在Delphi6中,新建一个application
2、加入两个DataModule
3、然后设定:TDataModule3 = class(TDataModule2)
4、保存所有的文件后(你现在可以编译这个Project,不会提示任何问题),在Delphi的File菜单中选择Close All
5、再打开这个Project,打开Unit3,令人无法理解的事情发生了:你会发现DataModule3变成了一个Form。如果你编译程序,那么将会出现Property color does not exist的错误提示,这个Project将无法再编译。

想知道原因或有其它的方法能解决DataModule的继承
 
1.菜单File->New->Other->你的软件工程名->要继承DataModule
 
1.打开Unit3
2.F12
3.Alt+F12
看看这个你就明白了
inherited DataModule3: TDataModule3
OldCreateOrder = True
Left = 450
Top = 228
end

inherited DataModule3: TDataModule3
不用object
 
注意了,dfm文件也要相应相改, Alt+F12, 或者在菜单中New inherited 操作
 
还没解决吗??????????????????????????
还不给分??????????????????????????
 
为什么要这样呢?TDataModule3 = class(TDataModule2) 为什么不直接继承?
 
To 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.
 
多人接受答案了。
 
后退
顶部