yanghai0437这位朋友,你是说invalid_handle_value和0是同一个意思了,那么这段程序<br>我又糊涂了!!能否QQ聊,我的:22330699<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> RadioGroup1: TRadioGroup;<br> Button1: TButton;<br> Button2: TButton;<br> Memo1: TMemo;<br> Memo2: TMemo;<br> Button3: TButton;<br> Button4: TButton;<br> Label1: TLabel;<br> Label2: TLabel;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button4Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure OpenComm; //打开通信端口<br> end;<br><br>var<br> Form1: TForm1;<br> hComm: THandle;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> opencomm;<br>end;<br><br>//以下是打开通信端口的程序<br>procedure TForm1.OpenComm;<br>var<br> cc:TCOMMCONFIG;<br> Temp:string;<br><br>begin<br> Temp:='COM'+inttostr(radiogroup1.ItemIndex+1); // 选择所要打开的COM<br> memo1.Text:=temp;<br> hComm:=CreateFile(PChar(Temp), GENERIC_READ or GENERIC_WRITE,<br> 0, nil, OPEN_EXISTING, 0, 10); // 打开COM<br> if (hComm =invalid_handle_value) then begin // =================>>>>>>>>>>和下面对应解释一下<br> MessageBox (0, '打开通信端口错误!!','',MB_OK);<br> exit;<br> end;<br><br> GetCommState(hComm,cc.dcb); // 得知目前COM 的状态<br> cc.dcb.BaudRate:=CBR_9600; // 设置波特率为9600<br> cc.dcb.ByteSize:=8; // 字节为 8 bit<br> cc.dcb.Parity:=NOPARITY; // Parity 为 None<br> cc.dcb.StopBits:=ONESTOPBIT; // 1 个Stop bit<br><br> if not SetCommState(hComm, cc.dcb) then begin// 设置COM 的状态<br> MessageBox (0, '通信端口设置错误!!!','',MB_OK);<br> CloseHandle(hComm);<br> exit;<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> SetCommMask(hcomm,$0);<br> CloseHandle(hComm);<br> close;<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>var<br> Temp : string;<br> inbuff: array[0..2047] of Char;<br> nBytesRead, dwEvent, dwError:LongWORD ;<br> cs:TCOMSTAT;<br>begin<br> ClearCommError(hComm,dwError,@CS); //取得状态<br> // 数据是否大于我们所准备的Buffer<br> if cs.cbInQue > sizeof(inbuff) then begin<br> PurgeComm(hComm, PURGE_RXCLEAR); // 清除COM 数据<br> exit;<br> end;<br> ReadFile(hComm, inbuff,cs.cbInQue,nBytesRead,nil); // 接收COM 的数据<br> //转移数据到变量中<br> Temp:=Copy(inbuff,1,cs.cbInQue);<br> memo2.Text :=Temp; // 将数据显示于Memo1 上<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> Temp:string;<br> lrc:LongWord;<br>begin<br> if (hComm=0) then exit; //检查Handle值=================================>>>>>>>>>>>>><br> Temp:=memo1.Text ;//取得传送的字符串<br> //实际的传送动作<br> WriteFile(hComm,PChar(Temp)^,Length(Temp), lrc, nil); // 送出数据<br><br>end;<br><br>end.<br><br>======================》》》》》》》所在行怎么解释呀??