unit Unit2;//数据模块interfaceuses
  SysUtils, Classes, DB, DBTables;type
  TDataModule2 = class(TDataModule)
    Database1: TDatabase;
    Table1: TTable;
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  DataModule2: TDataModule2;implementation{$R *.dfm}end.
-==============================================
unit Unit1;//一个frominterfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationuses
  unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
   DataModule2.Table1.Open;//这里出错出错信息在下面!
end;end.
'
思路:我是想将所有的Ttable,Tquery,database放在数据模块中
然后在每个窗体调用,可我在这个form用时,打开table出错.
我的数据库有以连的上odbc,table也可连上,这是什么问题请指教!!!错误: project project1.exe raised exception class EAccessViolation with message access violation at address 00482a2b in module project1.exe read of address 0000005c .process stopped. use step or run to continue.

解决方案 »

  1.   

    先创建DataModule,再使用:
    try
      DataModule2 := TDataModule2.Create(nil);
      DataModule2.Table1.Open;//这里出错出错信息在下面!
    finally
      DataModule2.Free;
    end;
      

  2.   

    Wally_wu(韦利) 还是不行!!!出错信息差不多。
    我是用delphi7的,数据库sql server 我直接用控件链接都可成功!
      

  3.   

    试试让DataModule由系统自动创建(位置在主窗体之前)。
      

  4.   

    project project1.exe raised exception class Ecomponenterror with message a component named database1 already exists.process stopped. use step or run to continue.
    加到工程里面后还是出错!
      

  5.   

    我搞定了忘了在工程里载入unit2这个数据模板文件了!!!