X
xiaoyaozh
Unregistered / Unconfirmed
GUEST, unregistred user!
本人第一次用DELPHI编程,在一个程序里用串口发送和接收显示数据
但程序并不能正确显示,问题出在哪儿?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
MSComm1: TMSComm;
Button1: TButton;
procedure MSComm1Comm(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MSComm1.CommPort:=2;
if MSComm1.PortOpen=False then
MSComm1.PortOpen:=True;
MSComm1.Output:='This is a text';
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var recstr:Olevariant;
begin
if MSComm1.commEvent=2 then
begin
recstr:=MSComm1.input;
Memo1.text:=Memo1.Text + recstr;
end;
end;
end.
但程序并不能正确显示,问题出在哪儿?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
MSComm1: TMSComm;
Button1: TButton;
procedure MSComm1Comm(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MSComm1.CommPort:=2;
if MSComm1.PortOpen=False then
MSComm1.PortOpen:=True;
MSComm1.Output:='This is a text';
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var recstr:Olevariant;
begin
if MSComm1.commEvent=2 then
begin
recstr:=MSComm1.input;
Memo1.text:=Memo1.Text + recstr;
end;
end;
end.