自定义了一个类(无窗体单元),在其中声明了一个adoconnection,然后引用,出错,请大家诊断一下代码 ( 积分: 0 )

  • 主题发起人 lanchong
  • 开始时间
L

lanchong

Unregistered / Unconfirmed
GUEST, unregistred user!
类的定义:
type
Tdataconfig=class
myconn:tadoconnection;
myquery:tadoquery;
procedure dataconfig();
procedure open();
procedure close();
procedure openquery(str_sql:string);
procedure closequery();
procedure execquery(str_sql:string);
public
constructor create;
end;
下面引用时,在 myconn.LoginPrompt:=false;一行出错:
procedure tdataconfig.Open();
const
link_str='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=%s;Initial Catalog=%s;Data Source=%s';
begin
try
InitProgramMessage;
InitSystemWorkground;
myconn.LoginPrompt:=false;
myconn.Connected:=false;
myconn.ConnectionString:=Format(link_str,[RemoteDatabaseUser,RemoteDatabaseName,RemoteDatabaseServerName]);
myconn.Connected := True;
except Application.MessageBox('远程数据库连接失败!', '异常', MB_OK + MB_ICONINFORMATION);
end;
end;
 
Q

qnaqbgss

Unregistered / Unconfirmed
GUEST, unregistred user!
加一句:
myconn:=tadoconnection.create;
 
B

Buddy.Sun

Unregistered / Unconfirmed
GUEST, unregistred user!
而且应该在Tdataconfig的create里创建,包括myquery
还有还有,最后记得释放
 
Z

zwz_good

Unregistered / Unconfirmed
GUEST, unregistred user!
myconn对象没有创建
qnaqbgss, 正解
 
B

bjf2001

Unregistered / Unconfirmed
GUEST, unregistred user!
tadoconnection动态创建一下,就没有问题了
 
顶部