我安装了SPCOMM,在SYSTEM里也可以找到,但在使用时会出错
源码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm;
type
Tfcomm = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Comm1: TComm;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure comm1receivedata(sender:tobject;buffer
ointer;bufferlength:word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fcomm: Tfcomm;
i:integer;
viewstring:string;
rbuf,sbuf:array[1..6] of byte;
implementation
{$R *.dfm}
procedure senddata;
var
i:integer;
commflg:boolean;
begin
viewstring:='';
commflg:=true;
for i:=1 to 6 do
begin
if not fcomm.comm1.writecommdata(@sbuf
,1) then
begin
commflg:=false;
break;
end;
sleep(2);
viewstring:=viewstring+inttohex(sbuf,2)+'';
end;
viewstring:='发送'+viewstring;
fcomm.memo1.lines.add(viewstring);
fcomm.memo1.lines.add('');
if not commflg then messagedlg('发送失败',mterror,[mbyes],0);
end;
procedure TFCOMM.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i:integer;
begin
viewstring:='';
move(buffer^,pchar(@rbuf^),bufferlength);
for i:=1 to bufferlength do
viewstring:=viewstring+inttohex(rbuf,2)+'';
viewstring:='接受'+viewstring;
memo1.lines.add(viewstring);
memo1.lines.add('');
end;
procedure Tfcomm.FormShow(Sender: TObject);
begin
comm1.StartComm;
end;
procedure Tfcomm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;
procedure Tfcomm.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($f0);
sbuf[2]:=byte($01);
sbuf[3]:=byte($ff);
sbuf[4]:=byte($ff);
sbuf[5]:=byte($01);
sbuf[6]:=byte($0f);
senddata;
end;
end.
它会在move(buffer^,pchar(@rbuf^),bufferlength);这行提示出错
Build
[Error] Unit1.pas(63): Pointer type required
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
请问这个怎么决解?