没有分了,但是还有一个问题呀。 这里应该有好心人吧?(0分)

  • 主题发起人 coolingxyz
  • 开始时间
C

coolingxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
//我的一个线程
uses
Classes, SysUtils, Forms, mystruct, Windows, ComCtrls, DB, ADODB, Messages, ActiveX;
Function Tmythread.Query(PNode : TTreeNode) : Boolean;
var
adoq : TADOQuery;
begin
try
CoInitialize(nil);
try
with adoqdo
begin
ConnectionString := main.constr;
//这里就出错了,在别的单元里用好的。
close;
sql.Clear;
case PNode.Level of
nlRoot :
begin
sql.Add('Select 命名 From CcName where IP地址 = :p0 and 类型 = :p1');
Parameters[0].Value := PStrIp(PNode.Data).Ip;
Parameters[1].Value := IpMm;
try
open;
if Not eof then
begin
first;
PNode.Text := Fields[0].AsString;
end;
finally
close;
end;
end;
nlJj :
begin
sql.Add('Select 命名 From CcName where IP地址 = :p0 and 机架编号 = :p1 and 类型 = :p2');
Parameters[0].Value := PStrIp(PNode.Parent.Data).Ip;
Parameters[1].Value := IntToStr(PStrJj(PNode.Data).JjNo);
Parameters[2].Value := JjMm;
try
open;
if Not eof then
begin
first;
PNode.Text := Fields[0].AsString;
end;
finally
close;
end;
end;
nlCc :
begin
sql.Add('Select 命名 From CcName where IP地址 = :p0 and 机架编号 = :p1 and 插槽编号 = :p2 and 类型 = :p3');
Parameters[0].Value := PStrIp(PNode.Parent.Parent.Data).Ip;
Parameters[1].Value := IntToStr(PStrJj(PNode.Parent.Data).JjNo);
Parameters[1].Value := IntToStr(PStrCc(PNode.Data).CcNo);
Parameters[3].Value := CcMm;
try
open;
if Not eof then
begin
first;
PNode.Text := Fields[0].AsString;
end;
finally
close;
end;
end;
end;
end;
//with
finally
ADOq.free;
end;
finally
CoUninitialize;
result := True;
end;
end;

编译能通过的。
运行错误是
Project wangguan.exe raised exception class EAccessViolation with message 'Access violation at address 004E44AC in moudule'
Wangguan.exe'.Read of address 000001A0'.Process stopped,use step or run to continue.
 
抱地址访问错啊,是adoq没有被创建:)
在开始加上:
adoq := TADOQuery.Create(nil);
 
我现在把connstr用参数传进来了,还是不行呀。怎么回事?
type
Tmythread = class(TThread)
private
PFhIp : PStrIp;
constr : String;
rec : Boolean;
protected
procedure Execute;
override;
Function Query( PNode: TTreeNode) : Boolean;
Public
constructor Create(TFhIp : TstrIp;
Connstr : String;
recording : Boolean);
Destructor Destroy;
Override;
end;

procedure Tmythread.Execute;
begin
{ Place thread code here }
FreeOnTerminate := True;
//线程做完后终止
if not terminated then
Stordata;
end;

Function Tmythread.Query(PNode : TTreeNode) : Boolean;
var
adoq : TADOQuery;
begin
try
CoInitialize(nil);
try
with adoqdo
begin
ConnectionString := constr;
Active := False;
sql.Clear;
//其他操作。
end;
//with
finally
ADOq.free;
end;
finally
CoUninitialize;
result := True;
end;
end;
 
ADOq 这个对象没有创建,怎么用,老兄,chenxz 说的对,先Create这个对象!!!
 
接受答案了.
 
顶部