函数返回值问题(50分)

  • 主题发起人 主题发起人 rcazy
  • 开始时间 开始时间
R

rcazy

Unregistered / Unconfirmed
GUEST, unregistred user!
做了一个这样的函数
function TForm1.openport(T:TCOMPORT; connect:boolean; commfile:thandle; xport:Tcomport):boolean;
var S : string;
size : dWord;
Buffer : PCommConfig;

DCB : TDCB;
Config : String;
CommTimeouts : TCommTimeouts;

Begin if connect Then closeport(t, connect, commfile);
// open communication
CommFile := CreateFile(Pchar(t.COMNAME), Generic_Write + Generic_Read , 0, nil, Open_Existing, File_Attribute_Normal,FILE_FLAG_OVERLAPPED);
connect := (CommFile <> INVALID_HANDLE_VALUE);
If connect Then
Begin If Not(setupComm(CommFile,256,256)) Then ShowMessage('Communicatoin Setup Error!');
If Not(GetCommState(CommFile,dcb)) Then ShowMessage('Communication Get State Error!');
Config := 'baud='+T.comspeed+' parity='+copy(t.comparity,1,1)+' data='+t.combit+' stop='+t.comstop;
If Not(BuildCommDCB(@Config[1],DCB)) Then ShowMessage('Communication Build DCB Error!');
If Not (SetCommState(CommFile, DCB)) Then ShowMessage('Communication Set New State Error!');
with CommTimeouts Do Begin
ReadIntervalTimeout := 0;
ReadTotalTimeoutMultiplier := 0;
ReadTotalTimeoutConstant := 1000;
WriteTotalTimeoutMultiplier := 0;
WriteTotalTimeoutConstant := 1000;
End;
If Not(SetCommTimeouts(CommFile,CommTimeouts)) Then ShowMessage('Communication Set Time-out Error!');
xport := T;
End
Else ShowMessage('COM port not found or problem!');
Result := connect;
我想在调用
openport(Comport,isconnect,hcommfile,port)
返回出Comport,isconnect,hcommfile,port的值
 
定义为:
function TForm1.openport(T:TCOMPORT; connect:boolean; commfile:thandle; xport:Tcomport;var Comport,isconnect,hcommfile,port : 你的类型):boolean; {openport}

用var 定义的即为你的返回值
 
function TForm1.openport(var T:TCOMPORT; var connect:boolean; var commfile:thandle; var xport:Tcomport):boolean;
改成這樣嗎?
不可以执行吧
"var Comport,isconnect,hcommfile,port : 你的类型"
不就是上面 T:TCOMPORT; connect:boolean; commfile:thandle; xport:Tcomport
 
返回值只能是boolean数据类型
 
那我想调用openport(Comport,isconnect,hcommfile,port)返回Comport,isconnect,hcommfile,port这四个值时怎么办好?这四个值我在PUBLIC里设置的,整个过程都要调用
 
function TForm1.openport(var T:TCOMPORT; var connect:boolean; var commfile:thandle; var xport:Tcomport):boolean;
 
多人接受答案了。
 
后退
顶部