delphi4下的串口通迅为何与delphi3下的不同? >:-((100分)

  • 主题发起人 主题发起人 徐磊
  • 开始时间 开始时间

徐磊

Unregistered / Unconfirmed
GUEST, unregistred user!
我在DELPHI3下的程序:
hcom:=createfile('com1',generic_read or generic_write,0,nil,open_existing,
file_flag_overlapped,0)
timeout.readintervaltimeout:=10;
timeout.readtotaltimeoutmultiplier:=20;
timeout.readtotaltimeoutconstant:=30;
setcommtimeouts(hcom,timeout);
setevent(hcom);
dataout:='S';
buffersize:=4096;
writefile(hcom,dataout,1,buffersize,@overlapped);
readfile(hcom,datain,1,buffersize,@overlapped);
closehandle(hcom);
用DELPHI4下编译,在writefile(),readfile()行上均产生如下错误(光标停在@前):
[Error] U_com.pas(48): Types of actual and formal var parameters must be identical
但两种开发环境中对它们的说明都和下面一样(详细解释有点不同,不过好像没关系)
BOOL ReadFile(
HANDLE hFile, // handle of file to read
LPVOID lpBuffer, // address of buffer that receives data
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // address of number of bytes read
LPOVERLAPPED lpOverlapped // address of structure for data
);
注:buffersize曾被我设为指针,可惜没用;另外overlapped前加不加@没关系,为何?
前一次把问题写错了位置,又没加分,实在不好意思! :-p
 
var
hcom:thandle;
timeout:TCommTimeouts;
dataout,datain:pchar;
overlapped:POverlapped;
buffersize:dword;
begin

hcom:=createfile('com1',generic_read or generic_write,0,nil,open_existing,
file_flag_overlapped,0);
timeout.readintervaltimeout:=10;
timeout.readtotaltimeoutmultiplier:=20;
timeout.readtotaltimeoutconstant:=30;
setcommtimeouts(hcom,timeout);
setevent(hcom);
dataout:='S';
buffersize:=4096;
writefile(hcom,dataout,1,buffersize,@overlapped);
readfile(hcom,datain,1,buffersize,@overlapped);
closehandle(hcom);

end;
在delphi5上运行通过
 
sorry,原来写的有问题
var
hcom:thandle;
timeout:TCommTimeouts;
dataout,datain:pchar;
overlapped:POverlapped;
buffersize:dword;
begin
hcom:=createfile('com1',generic_read or generic_write,0,nil,open_existing,
file_flag_overlapped,0);
timeout.readintervaltimeout:=10;
timeout.readtotaltimeoutmultiplier:=20;
timeout.readtotaltimeoutconstant:=30;
setcommtimeouts(hcom,timeout);
setevent(hcom);
dataout:='S';
getmem(overlapped,sizeof(tOverlapped));
buffersize:=4096;
getmem(datain,4096);
if writefile(hcom,dataout,1,buffersize,overlapped) then
showmessage('write right');
if readfile(hcom,datain,1,buffersize,overlapped) then
showmessage('read right');
freemem(datain);
freemem(overlapped);
closehandle(hcom);
end;
@type表示一个地址(如0012:0034),若overlapped:poverlapped不应用@
若overlapped:toverlapped then use @overlapped
 
关键看你的overrlapped定义是什么类型了.
应当在d3中也通不过呀?!
 
在WINDOWS.PAS 中
POVERLAPPED=^TOVERLAPPED
所以你用POVERLAPPED时,不用@(ADDR FUNCTION)
当用TOVERLAPPED 时,就用@(ADDR FUNCTION)

 
又是参数类型问题. 呵呵D4增强了var型参数类型的判断, 必须完全一致.
比如THandle, Integer, LongInt, Cardinal...在d3下用做var型参数时可以混
用, 但在d4下这样做是不允许的.
比如: 原型规定的如果是THandle型, d4下传递var参数时不能传个Integer型
的参数进去. 但在d3下是允许的.
 
多人接受答案了。
 
后退
顶部