H
huwei1118
Unregistered / Unconfirmed
GUEST, unregistred user!
本意是从线程中调用读com口函数,现没接设备,就从文本文件里读了,readcom()函数返回的是一个结构体.请高手指点
报错如下:
Project Project1.exe raised exception class EAccessViolation with message' Access violation at address 00381c83 in module 'commodual.dll',write of address 0000006A'. Process stopped.Use Step or Run to continue
--------------------------------------------------------------------------
-----------------------------------------------------------------------------------
主程序的部分内容
type
TestThread=class(TThread)
private
protected
procedure Execute;
override;
public
constructor Create(ch:integer);overload;
end;
var
NewThreadObject:TestThread;
tempreadcominfo:Treadcominfo;
tempreadcominfoarry:array of Treadcominfo;
constructor TestThread.Create(ch:integer);
begin
create(false);
end;
procedure TestThread.Execute;
begin
while not Terminateddo
begin
//调用读com口函数
tempreadcominfo:=readcom();//readcom()是dll里的一个函数,返回值为一个结构体
end;
end;
procedure TForm1.BTNthreadstartClick(Sender: TObject);
begin
if not Assigned(NewThreadObject) then
NewThreadObject:= TestThread.Create(1);
end;
-----------------------------------------------------------------------------
TReadComInfo=record{设置读com口信息结构体}
Date :String;
Time :String;
NP :String;
TK :String;
Stat :String;
Ext :String;
CalledNumber :String;
Duration :String;
Ring :String;
Acc :String;
end;
-----------------------------------------------------------------------------
以下是dll里的一些内容
var
ReadComInfo:TReadComInfo;
ReadComInfoarray:array of Treadcominfo;
function ReadCom():TReadComInfo;stdcall;
var
sla:TStringList;
i,j :integer;
//文本文件中的相应的10个字段
strDate,strTime,strNP,strTK,strStat,strEXT,strcallnum,strDur,strRing,strAcc:String;
begin
sla := TStringList.Create;
//opendialog1.Execute;
sla.LoadFromFile('number.txt');
i:=sla.Count;
strDate:='';
strTime:='';
strNP :='';
strTK :='';
strStat :='';
strEXT :='';
strcallnum :='';
strDur :='';
strRing :='';
strAcc:='';
setlength(ReadComInfoarray,200);
for j:=0 to i-1do
//取相应文本文件的字段值
begin
strDate:=copy(sla.Strings[j],3,10);
strTime:=copy(sla.Strings[j],14,5);
strNp:=copy(sla.Strings[j],21,1);
strTK:=copy(sla.Strings[j],23,2);
strStat:=copy(sla.Strings[j],26,4);
strExt:=copy(sla.Strings[j],32,4);
strCallnum:=trim(copy(sla.Strings[j],38,14));
strDur:=copy(sla.Strings[j],60,8);
strRing:=copy(sla.Strings[j],70,5);
strACC:=copy(sla.Strings[j],77,3);
ReadComInfoarray[j].Date:=strDate;
ReadComInfoarray[j].Time:=strTime;
ReadComInfoarray[j].NP:=strNP;
ReadComInfoarray[j].TK:=strTk;
ReadComInfoarray[j].Stat:=strStat;
ReadComInfoarray[j].Ext:=StrExt;
ReadComInfoarray[j].CalledNumber:=StrCallNUM;
ReadComInfoarray[j].Duration:=strDur;
ReadComInfoarray[j].Ring:=strRing;
ReadComInfoarray[j].Acc:=strAcc;
ReadComInfo:=ReadComInfoarray[j];
end;
result:=ReadComInfo;
end;
-----------------------------------------------------------------------
以下是number.txt的内容
01/06/2006 11:46 1 02 HOLD 0118 038538876 00:01:19 00:00 001
01/06/2006 11:48 E 02 PICK 0106 00:00:36 00:00
01/06/2006 11:48 E 01 OUT 0108 117 00:00:12 00:00
01/06/2006 11:51 1 02 IN 0117 038538876 00:00:08 00:05
01/06/2006 11:51 1 02 HOLD 0117 038538876 00:00:10 00:00
01/06/2006 11:52 E 09 OUT 0106 27180 00:00:04 00:00
01/06/2006 11:52 E 10 OUT 0106 00 00:00:06 00:00
01/06/2006 11:52 E 11 OUT 0106 2718 00:00:03 00:00
01/06/2006 11:52 E 12 OUT 0106 271 00:00:04 00:00
01/06/2006 11:51 1 02 PICK 0119 038538876 00:01:51 00:00
01/06/2006 11:53 1 02 HOLD 0119 038538876 00:00:29 00:00
01/06/2006 11:52 E 04 OUT 0106 27187676 00:01:34 00:00
01/06/2006 11:49 E 03 IN 0132 00:05:05 00:10
01/06/2006 11:54 E 13 OUT 0118 2729 00:00:03 00:00
01/06/2006 11:54 1 03 IN 0104 25962394 00:00:16 00:05
01/06/2006 11:54 1 03 HOLD 0104 25962394 00:00:21 00:00
--------------------------------------------------------------------------------
报错如下:
Project Project1.exe raised exception class EAccessViolation with message' Access violation at address 00381c83 in module 'commodual.dll',write of address 0000006A'. Process stopped.Use Step or Run to continue
--------------------------------------------------------------------------
-----------------------------------------------------------------------------------
主程序的部分内容
type
TestThread=class(TThread)
private
protected
procedure Execute;
override;
public
constructor Create(ch:integer);overload;
end;
var
NewThreadObject:TestThread;
tempreadcominfo:Treadcominfo;
tempreadcominfoarry:array of Treadcominfo;
constructor TestThread.Create(ch:integer);
begin
create(false);
end;
procedure TestThread.Execute;
begin
while not Terminateddo
begin
//调用读com口函数
tempreadcominfo:=readcom();//readcom()是dll里的一个函数,返回值为一个结构体
end;
end;
procedure TForm1.BTNthreadstartClick(Sender: TObject);
begin
if not Assigned(NewThreadObject) then
NewThreadObject:= TestThread.Create(1);
end;
-----------------------------------------------------------------------------
TReadComInfo=record{设置读com口信息结构体}
Date :String;
Time :String;
NP :String;
TK :String;
Stat :String;
Ext :String;
CalledNumber :String;
Duration :String;
Ring :String;
Acc :String;
end;
-----------------------------------------------------------------------------
以下是dll里的一些内容
var
ReadComInfo:TReadComInfo;
ReadComInfoarray:array of Treadcominfo;
function ReadCom():TReadComInfo;stdcall;
var
sla:TStringList;
i,j :integer;
//文本文件中的相应的10个字段
strDate,strTime,strNP,strTK,strStat,strEXT,strcallnum,strDur,strRing,strAcc:String;
begin
sla := TStringList.Create;
//opendialog1.Execute;
sla.LoadFromFile('number.txt');
i:=sla.Count;
strDate:='';
strTime:='';
strNP :='';
strTK :='';
strStat :='';
strEXT :='';
strcallnum :='';
strDur :='';
strRing :='';
strAcc:='';
setlength(ReadComInfoarray,200);
for j:=0 to i-1do
//取相应文本文件的字段值
begin
strDate:=copy(sla.Strings[j],3,10);
strTime:=copy(sla.Strings[j],14,5);
strNp:=copy(sla.Strings[j],21,1);
strTK:=copy(sla.Strings[j],23,2);
strStat:=copy(sla.Strings[j],26,4);
strExt:=copy(sla.Strings[j],32,4);
strCallnum:=trim(copy(sla.Strings[j],38,14));
strDur:=copy(sla.Strings[j],60,8);
strRing:=copy(sla.Strings[j],70,5);
strACC:=copy(sla.Strings[j],77,3);
ReadComInfoarray[j].Date:=strDate;
ReadComInfoarray[j].Time:=strTime;
ReadComInfoarray[j].NP:=strNP;
ReadComInfoarray[j].TK:=strTk;
ReadComInfoarray[j].Stat:=strStat;
ReadComInfoarray[j].Ext:=StrExt;
ReadComInfoarray[j].CalledNumber:=StrCallNUM;
ReadComInfoarray[j].Duration:=strDur;
ReadComInfoarray[j].Ring:=strRing;
ReadComInfoarray[j].Acc:=strAcc;
ReadComInfo:=ReadComInfoarray[j];
end;
result:=ReadComInfo;
end;
-----------------------------------------------------------------------
以下是number.txt的内容
01/06/2006 11:46 1 02 HOLD 0118 038538876 00:01:19 00:00 001
01/06/2006 11:48 E 02 PICK 0106 00:00:36 00:00
01/06/2006 11:48 E 01 OUT 0108 117 00:00:12 00:00
01/06/2006 11:51 1 02 IN 0117 038538876 00:00:08 00:05
01/06/2006 11:51 1 02 HOLD 0117 038538876 00:00:10 00:00
01/06/2006 11:52 E 09 OUT 0106 27180 00:00:04 00:00
01/06/2006 11:52 E 10 OUT 0106 00 00:00:06 00:00
01/06/2006 11:52 E 11 OUT 0106 2718 00:00:03 00:00
01/06/2006 11:52 E 12 OUT 0106 271 00:00:04 00:00
01/06/2006 11:51 1 02 PICK 0119 038538876 00:01:51 00:00
01/06/2006 11:53 1 02 HOLD 0119 038538876 00:00:29 00:00
01/06/2006 11:52 E 04 OUT 0106 27187676 00:01:34 00:00
01/06/2006 11:49 E 03 IN 0132 00:05:05 00:10
01/06/2006 11:54 E 13 OUT 0118 2729 00:00:03 00:00
01/06/2006 11:54 1 03 IN 0104 25962394 00:00:16 00:05
01/06/2006 11:54 1 03 HOLD 0104 25962394 00:00:21 00:00
--------------------------------------------------------------------------------