未找到 TADOConnection / TADOTable 类
好的,我的应用程序运行得很好,直到我决定通过创建 DataModule 表单并将所有数据库组件移至其中来稍微清理设计时表单。我正在使用 Delphi XE2 Update 1 和这些组件:TADOConnection、TADOTable、TADOQuery、TADOCommand。当我尝试使用 DataModule 表单(而不是主表单)上的上述命名组件首次运行应用程序时,在执行 DPR 中的这一行时,它现在会返回错误:
Application.CreateForm( TDataModule1, DataModule1);
引发的错误是未找到 TADOCOnnection 类。。现在,我删除了 TADOConnection 并将其重新添加到 DataModule 表单中,它现在引发了一个不同的错误:未找到 Class TADOTable。,但我认为这只是因为 DataModule 上的创建顺序已更改现在,TADOTable
是在表单上创建的第一个对象。
我的 DataModule uses
子句是:
uses System.SysUtils、System.Classes、Data.Win.ADODB、Data.DB;
我读过其他据说包含 ADODB 的帖子使用子句中的 DB 来克服此错误,但这似乎没有帮助。
我的完整 DPR 文件是:
program Project1;
uses
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {DataModule1: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TDataModule1, DataModule1);
Application.Run;
end.
我什至尝试从创建 DataModule 的 DPR 文件中删除行并在主窗体中手动执行此操作,但当我收到相同的错误消息时,情况就会发生变化。
除了将所有组件移回主窗体之外,我不确定下一步要尝试什么。 DataModule 表单在 XE2 中的工作方式与 Delphi 的早期版本不同吗?为什么当组件位于主表单上时,不会引发相同的 TADOConnection 和 TADOTable 类未找到消息?
非常感谢任何想法或见解。
詹姆斯
Okay, so my application was working just fine until I decided to clean up the design-time form a bit by creating a DataModule form and moving all database components to it. I'm using Delphi XE2 Update 1 and these components, TADOConnection, TADOTable, TADOQuery, TADOCommand. As soon as I tried to run the app for the first time with the above named components on the DataModule form, instead of the main form, it now returns an error when this line from the DPR is executed:
Application.CreateForm(TDataModule1, DataModule1);
The error raised is Class TADOCOnnection not found.. Now that I removed and re-added the TADOConnection to the DataModule form, it now raises a different error: Class TADOTable not found., but I think that is just because the create order has changed on the DataModule and a TADOTable
is now the first object that is created on the form.
My uses
clause from the DataModule is:
uses System.SysUtils, System.Classes, Data.Win.ADODB, Data.DB;
I read other posts that said to include ADODB and DB in the uses clause to overcome this error, but that doesn't seem to help.
My full DPR file is:
program Project1;
uses
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {DataModule1: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TDataModule1, DataModule1);
Application.Run;
end.
I even tried removing the line from the DPR file that creates the DataModule and doing that manually in the main form, but that just changes when I get the same error message(s).
I'm not sure what to try next, aside from moving all the components back to the main form. Don't DataModule forms work the same in XE2 as prior versions of Delphi, and why aren't the same TADOConnection and TADOTable class not found messages raised when the components are on the main form?
Any thoughts or insights are very much appreciated.
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
启动一个新项目并向其中添加一个
DataModule
。将TADOConnection
和TADOTable
放到DataModule
上。保存项目并查看哪些单元被添加到DataModule
的使用中。如果您的项目编译并成功运行,请将单元名称从该测试项目复制到工作项目的DataModule
中,然后重试。如果这没有帮助,我只能猜测您的库路径存在一些问题。我没有 Delphi XE2 来尝试这个,所以我只是猜测。Start a new project and add to it a
DataModule
. DropTADOConnection
andTADOTable
on theDataModule
. Save the project and see which units get added into uses ofDataModule
. If Your project compiles and runs successfully, copy the unit names from that test project into your working project'sDataModule
and try again. If that doesn't help, I can only guess that you have some issues with library paths. I don't have Delphi XE2 to try this, so I'm just guessing.在创建一个没有任何问题的新项目时,我终于发现了我引入到我自己的代码中的问题。
我在 DataModules 单元/类中添加了一个特殊方法。我需要传递一个枚举类型作为参数,因此我在类的范围内创建了枚举,如下所示:
我将枚举添加到类中,因为它不需要需要具有全局范围。无论如何...您会注意到我在枚举后面添加了
public
范围标识符。那是我的错误。我假设表单上的组件是公共的,但这是错误的。它们已发布
。将范围标识符更改为published
解决了问题,因为现在组件包含在 RTTI 中,而在运行时创建表单时需要 RTTI。希望这对其他人有帮助。
詹姆斯
In creating a new project, which worked without any issues, I finally found the problem that I introduced into my own code.
I had added a special method in the DataModules unit / class. I needed to pass an enumerated type as the parameter, so I created the enumeration in the scope of the class, like this:
I added the enum to the class because it did not need to have global scope. Anyway... You'll notice that I added the
public
scope identifier after the enum. That was my mistake. I assumed that components on a form arepublic
, but that is wrong. They arepublished
. Changing the scope identifier topublished
fixed the problem, because now the components are included in the RTTI, which is needed when a form is created at runtime.Hope this helps someone else.
James
可能是一个迟到的答案,但是您是否检查了相应 Datamodule 上的 ClassGroup ?在 IDE 中打开数据模块,单击它并检查 ObjectInspector 中的 ClassGroup 属性。
如果它没有设置为 Vcl.Controls.TControl,那么您可能需要将其更改为该值。这里的逻辑是,默认情况下,数据模块根本不绑定到任何框架,并且可以用于两者。因此,System.Classes.TPercient 的 ClassGroup 意味着您的数据模块是框架/平台无关的(您可以在 VCL 应用程序和 FMX 应用程序中使用它)。
ADO 组件集是 VCL 特定的,不能在 FMX 应用程序中使用,这意味着您不应使用 System.Classes.TPercient 作为数据模块的 ClassGroup,而应使用 Vcl.Controls.TControl。
也许这可能是您问题的根源?
Might be a late answer, but did you check which ClassGroup you have on the corresponding Datamodule ? Open the data module in your IDE, click on it and check the ClassGroup property in the ObjectInspector.
If it isn't set to Vcl.Controls.TControl, then you might want to change it to that. The logic here is that by default a Datamodule isn't bound to any framework at all an can be used for both. So a ClassGroup of System.Classes.TPersistent means that your data module is framework / platform independent (you could use it in a VCL app and in an FMX app).
The ADO set of components are VCL Specific and can't be used in an FMX app, which means you shouldn't use System.Classes.TPersistent as the ClassGroup for your data module, but use Vcl.Controls.TControl instead.
Maybe that might be the source of your problem ?
您可能使用数据集,但没有为此添加任何数据源
you may using a dataset but didn't add any dataSource for that