在dataconnection下面的代码如下:
procedure TData.DataModuleCreate(Sender: TObject);
var    ini:tIniFile;
       strserver,strname,strpassword:string;
begin
ini:=tinifile.Create(extractfilepath(paramstr(0))+'\cserver.ini');
strserver:=ini.ReadString('server','server','server');
strname:=ini.ReadString('name','name','sa');
strpassword:=ini.ReadString('password','password','');
try
adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='+strname+';Initial Catalog=studten;Data Source='+strserver+';password='+strpassword;
adoconnection1.Connected:=true;
except
exit;
end;
end; 
在程序窗口的代码procedure TForm1.FormCreate(Sender: TObject);
begin
   adoquery1.Connection:=data.ADOConnection1;
   adoquery1.Active:=true;
   adoquery1.Close;
   adoquery1.SQL.Clear;
   adoquery1.SQL.Add('select * form t_writes');
   adoquery1.Open;
end;
但每次运行的时间都会提示出错,
Project P1.exe raised exception class, EAccessVonlation with message' access violation at address 004A94F2 in moule p1.exe '. read of address 00000058.我是菜鸟,刚学不久,请赐教!是什么原因!

解决方案 »

  1.   

    打开工程文件,看TData是不是在TForm1之前Create了
      

  2.   

    首先给你指一个错误,在procedure TData.DataModuleCreate(Sender: TObject);中
    ini在函数结束的时候最好释放掉.ini.free;提示这种错误,就是对象没有创建就使用了,看样子好象是adoquery1没有创建吧。
    提出错误提示停在了那条语句上?
      

  3.   

    program P1;uses
      Forms,
      M1 in 'M1.pas' {Form1},
      date in 'date.pas' {DataModule2: TDataModule};{$R *.res}begin
      Application.Initialize;
      Application.CreateForm(TDataModule2, DataModule2);
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
      

  4.   

    多谢,我在project里面把那两个文件的位置调查了一下,就可以了。谢谢大家的帮助!
    只有100分,就平均分了。不好意思!