N
netbug
Unregistered / Unconfirmed
GUEST, unregistred user!
以下这段程序是在一个帖子中发现的:
Var
hCommFile : THandle;
Procedure TForm1.Button1Click(Sender : TObject);
Var
PhoneNumber : String;
CommPort : String;
NumberWritten : LongInt;
Begin
PhoneNumber := 'ATDT 010-62988861' + #13 + #10;
CommPort := 'COM2';
{打开 comm port}
hCommFile := CreateFile(PChar(CommPort),
GENERIC_WRITE,
0,
Nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
If hCommFile = INVALID_HANDLE_VALUE Then
Begin
ShowMessage('不能打开 ' + CommPort);
exit;
End;
{拨号}
NumberWritten := 0;
If WriteFile(hCommFile,
PChar(PhoneNumber)^,
Length(PhoneNumber),
NumberWritten,
Nil) = false Then Begin
ShowMessage('无法写 ' + CommPort);
End;
End;
但我编译时,在
If WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),NumberWritten,Nil) = false
出现了:
[Error] Types of actual and formal var parameters must be identical
后来我把这句该为:
If WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),@NumberWritten,Nil) = false
还是出现同样的错误,请问:我该如何解决?谢谢.
Var
hCommFile : THandle;
Procedure TForm1.Button1Click(Sender : TObject);
Var
PhoneNumber : String;
CommPort : String;
NumberWritten : LongInt;
Begin
PhoneNumber := 'ATDT 010-62988861' + #13 + #10;
CommPort := 'COM2';
{打开 comm port}
hCommFile := CreateFile(PChar(CommPort),
GENERIC_WRITE,
0,
Nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
If hCommFile = INVALID_HANDLE_VALUE Then
Begin
ShowMessage('不能打开 ' + CommPort);
exit;
End;
{拨号}
NumberWritten := 0;
If WriteFile(hCommFile,
PChar(PhoneNumber)^,
Length(PhoneNumber),
NumberWritten,
Nil) = false Then Begin
ShowMessage('无法写 ' + CommPort);
End;
End;
但我编译时,在
If WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),NumberWritten,Nil) = false
出现了:
[Error] Types of actual and formal var parameters must be identical
后来我把这句该为:
If WriteFile(hCommFile,PChar(PhoneNumber)^,Length(PhoneNumber),@NumberWritten,Nil) = false
还是出现同样的错误,请问:我该如何解决?谢谢.