通信编程问题,请各位高手帮帮忙。

gxlzx 2000-07-18 05:46:00
下面的程序在Delphi3中编译通过,在Delphi4中编译时出错:[Error] Modenf.pas(47): Types of actual and formal var parameters must be identical

代码如下(一个拔号程序):
unit Modenf;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

const
comPort='COM2';

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
hComm:THandle;
s:string;
i:longint;
begin
s:=' ';
if InputQuery('电话号码','请输入一个电话号码:',s) then
begin
s:='atdt'+s+#13;
hComm:=CreateFile(comPort,GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hComm=INVALID_HANDLE_VALUE then
begin
ShowMessage('无法打开'+comPort);
Exit;
end;
if not WriteFile(hComm,PChar(s)^,Length(s),i,nil)then
ShowMessage('无法写入'+comPort);
CloseHandle(hComm);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
hComm:THandle;
s:string;
i:Longint;
begin
s:='ath';
hComm:=CreateFile(comPort,GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if hComm=INVALID_HANDLE_VALUE then
begin
ShowMessage('无法打开'+comPort);
exit;
end;
if not WriteFile(hComm,PChar(s)^,Length(s),i,nil)then
ShowMessage('无法写入'+comPort);
CloseHandle(hComm);
end;

end.

请问是什么原因???
...全文
88 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
meijg 2000-07-18
  • 打赏
  • 举报
回复
测试过了,是你的数据类型有问题 ,i的类型改为 DWORD 或者 LONGWORD 而不是longint

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧