1

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

James L.
  • 9,384
  • 5
  • 38
  • 77

5 Answers5

2

Start a new project and add to it a DataModule. Drop TADOConnection and TADOTable on the DataModule. Save the project and see which units get added into uses of DataModule. If Your project compiles and runs successfully, copy the unit names from that test project into your working project's DataModule 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.

LightBulb
  • 964
  • 1
  • 11
  • 27
  • if all OP did was move some components, then indeed units missing from the datamodule's uses clause sh/would be the cause of the error message. – Marjan Venema Oct 23 '11 at 08:11
  • Your suggestion `LightBulb`, though not the answer, was helpful in tracking down the issue. I did as you suggested and created a new project from scratch, which did work. I'll post the full answer and explain. +1 for your suggestion. – James L. Oct 24 '11 at 23:52
1

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:

TDataModule1 = class(TDataModule)
type
  TMyEnum = (eOne, eTwo, eThree);
public
  ADOConnection1: TADOConnection;
  ... // more components added to the design window
  procedure MyMethod(const Param: TMyEnum);
end;

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 are public, but that is wrong. They are published. Changing the scope identifier to published fixed the problem, because now the components are included in the RTTI, which is needed when a form is created at runtime.

TDataModule1 = class(TDataModule)
type
  TMyEnum = (eOne, eTwo, eThree);
published // <- this fixes the "Class Not Found" at Runtime Error
  ADOConnection1: TADOConnection;
  ... // more components added to the design window
  procedure MyMethod(const Param: TMyEnum);
end;

Hope this helps someone else.

James

James L.
  • 9,384
  • 5
  • 38
  • 77
0
//You should begin creating the dataModule, so change your code like this:
'Application.Initialize; '
'Application.MainFormOnTaskbar := True;'
'Application.CreateForm(TDataModule1, DataModule1);'
'Application.CreateForm(TForm1, Form1); '

//There is a question I have:
//How do I use ADOConnection / ADOTable in combination with an access2010-database?
  • 1
    The problem wasn't whether the DataModule was being created, it was that its properties weren't being published properly, so the RTTI couldn't find them. See the previous answer to see what I mean. – James L. Apr 17 '12 at 00:59
  • As for your question -- the ADOConnection needs a valid connection string. You can use the property editor, which provides a wizard of sorts. Use the Microsoft Jet OLE DB Provider, which will let you select an Access database. Of course the ODBC Jet drivers need to be compatible with your Access 2010 database or it will not work. Once you can connect the ADOConnection, then you link the ADOTable to the connection, and the TableName property will list the available tables in the Access database. It's pretty intuitive once you select the MS Jet OLE provider... – James L. Apr 19 '12 at 15:28
0

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 ?

Stefaan
  • 492
  • 4
  • 19
  • Good feedback @Steffan, but the problem was that I changed the scope of the component section of the class declaration to public instead of the default scope of published, so the components were not included in the RTTI and couldn't be found by the EXE at runtime. – James L. May 15 '12 at 21:47
0

you may using a dataset but didn't add any dataSource for that