浴
浴火凤凰
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
MSComm2: TMSComm;
procedure FormCreate(Sender: TObject);
procedure MSComm2Comm(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
[red]ss:string;[/red]//定义为全局变量就好好的了.
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mscomm2.commport:=2 ;
mscomm2.settings:='9600,o,7,1';
mscomm2.inputlen:=1;
mscomm2.inputmode:=cominputmodetext;
mscomm2.portopen :=true;
mscomm2.rthreshold:=1;
end;
procedure TForm1.MSComm2Comm(Sender: TObject);
var
buffer:variant;
s1,s2,s3,s4:string;
c:char;
pos1,pos2:integer;
//但是ss定义在这里就不行
begin
case MSComm2.CommEvent of
comEvReceive:
begin
buffer:=mscomm2.input;
s1:=buffer;
c:=s1[1];
ss:=ss+c;
pos1:=pos('<',ss);
pos2:=pos('D',ss);
if (pos1>0) and (pos2>0) then
begin
mscomm2.rthreshold:=0;
s2:=copy(ss,pos1,pos2-pos1+1);
memo1.Lines.Add(s2);
//后面就不用看了,没什么问题.
s3:=copy(s2,2,6);
s4:=chr(10)+'>'+s3+'ok'+' '+'001'+chr(13);
mscomm2.output:=s4;
Memo2.Lines.Add(s4);
ss:='';
mscomm2.rthreshold:=1;
end;
end;
end;
end;
end.
我的目的是接收以"<"开头以'd'结尾的字符串.
现在的问题是这样的 如果 ss定义为全局变量就好好的
但是定义在procedure TForm1.MSComm2Comm(Sender: TObject);
var
这个下面就不行了
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
MSComm2: TMSComm;
procedure FormCreate(Sender: TObject);
procedure MSComm2Comm(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
[red]ss:string;[/red]//定义为全局变量就好好的了.
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mscomm2.commport:=2 ;
mscomm2.settings:='9600,o,7,1';
mscomm2.inputlen:=1;
mscomm2.inputmode:=cominputmodetext;
mscomm2.portopen :=true;
mscomm2.rthreshold:=1;
end;
procedure TForm1.MSComm2Comm(Sender: TObject);
var
buffer:variant;
s1,s2,s3,s4:string;
c:char;
pos1,pos2:integer;
//但是ss定义在这里就不行
begin
case MSComm2.CommEvent of
comEvReceive:
begin
buffer:=mscomm2.input;
s1:=buffer;
c:=s1[1];
ss:=ss+c;
pos1:=pos('<',ss);
pos2:=pos('D',ss);
if (pos1>0) and (pos2>0) then
begin
mscomm2.rthreshold:=0;
s2:=copy(ss,pos1,pos2-pos1+1);
memo1.Lines.Add(s2);
//后面就不用看了,没什么问题.
s3:=copy(s2,2,6);
s4:=chr(10)+'>'+s3+'ok'+' '+'001'+chr(13);
mscomm2.output:=s4;
Memo2.Lines.Add(s4);
ss:='';
mscomm2.rthreshold:=1;
end;
end;
end;
end;
end.
我的目的是接收以"<"开头以'd'结尾的字符串.
现在的问题是这样的 如果 ss定义为全局变量就好好的
但是定义在procedure TForm1.MSComm2Comm(Sender: TObject);
var
这个下面就不行了