在用SPCOM控件时遇到的这样的编译警告,请帮小弟我看看!
在用SPCOM控件时遇到的这样的编译警告,请帮我看看!!
我的程序里,是用Spcom控件的,注册了之后,在我的Form上放了一个,关于协议设置,我在界面上放了几个ComboBox控件,比如波特率,停止位和校验位等都是通过ComboBox里选择的,在Spcom里,它的属性,数据位,校验位,停止位都是枚举类型的,我下面的代码为什么会有个警告出现!
void __fastcall TForm1::BtnInitClick(TObject *Sender)
{
Comm-> StopComm();
Comm-> CommName = ComName;
Comm-> BaudRate = ComBaud;
Comm-> ByteSize = CmbDatabit-> Text.ToIntDef(_8);//警告
Comm-> Parity = CmbParity-> Text.ToIntDef(None) ;//警告
Comm-> StopBits = CmbStop-> Text.ToIntDef(_1); //警告
try
{
Comm-> StartComm();
}
catch(...)
{
Application-> MessageBoxA( "串口通信参数设置错误!\n现在串口停止工作。 ", "串口错误 ",0);
}
}
[C++ Warning] CommTestMain.cpp(48): W8018 Assigning int to TByteSize
[C++ Warning] CommTestMain.cpp(49): W8018 Assigning int to TParity
[C++ Warning] CommTestMain.cpp(50): W8018 Assigning int to TStopBits
请问如何修改!
------解决方案--------------------
//delphi的例子请参考
spcomm写端口
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, SPComm;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
StatusBar1: TStatusBar;
TabSheet1: TTabSheet;
Label1: TLabel;
EditCommName: TEdit;
Label2: TLabel;
bautrate: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
bytesize: TComboBox;
stopbits: TComboBox;
sendparty: TComboBox;
memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Comm1: TComm;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure bautrateExit(Sender: TObject);
procedure bytesizeChange(Sender: TObject);
procedure stopbitsChange(Sender: TObject);
procedure sendpartyChange(Sender: TObject);
private
{ Private declarations }
//procedure WMCOMMNOTIFY(var Message:Tmessage);message WM_COMMNOTIFY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
comm1.CommName:=editcommname.Text;
comm1.BaudRate:=strtoint(bautrate.Text);
comm1.ByteSize:=tbytesize(bytesize.ItemIndex);
comm1.StopBits:=tstopbits(stopbits.ItemIndex);
comm1.Parity:=tparity(sendparty.ItemIndex);
try
comm1.StartComm;
except
raise exception.Create( '打开串口错误 ');
end;
我的程序里,是用Spcom控件的,注册了之后,在我的Form上放了一个,关于协议设置,我在界面上放了几个ComboBox控件,比如波特率,停止位和校验位等都是通过ComboBox里选择的,在Spcom里,它的属性,数据位,校验位,停止位都是枚举类型的,我下面的代码为什么会有个警告出现!
void __fastcall TForm1::BtnInitClick(TObject *Sender)
{
Comm-> StopComm();
Comm-> CommName = ComName;
Comm-> BaudRate = ComBaud;
Comm-> ByteSize = CmbDatabit-> Text.ToIntDef(_8);//警告
Comm-> Parity = CmbParity-> Text.ToIntDef(None) ;//警告
Comm-> StopBits = CmbStop-> Text.ToIntDef(_1); //警告
try
{
Comm-> StartComm();
}
catch(...)
{
Application-> MessageBoxA( "串口通信参数设置错误!\n现在串口停止工作。 ", "串口错误 ",0);
}
}
[C++ Warning] CommTestMain.cpp(48): W8018 Assigning int to TByteSize
[C++ Warning] CommTestMain.cpp(49): W8018 Assigning int to TParity
[C++ Warning] CommTestMain.cpp(50): W8018 Assigning int to TStopBits
请问如何修改!
------解决方案--------------------
//delphi的例子请参考
spcomm写端口
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, SPComm;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
StatusBar1: TStatusBar;
TabSheet1: TTabSheet;
Label1: TLabel;
EditCommName: TEdit;
Label2: TLabel;
bautrate: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
bytesize: TComboBox;
stopbits: TComboBox;
sendparty: TComboBox;
memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Comm1: TComm;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure bautrateExit(Sender: TObject);
procedure bytesizeChange(Sender: TObject);
procedure stopbitsChange(Sender: TObject);
procedure sendpartyChange(Sender: TObject);
private
{ Private declarations }
//procedure WMCOMMNOTIFY(var Message:Tmessage);message WM_COMMNOTIFY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
comm1.CommName:=editcommname.Text;
comm1.BaudRate:=strtoint(bautrate.Text);
comm1.ByteSize:=tbytesize(bytesize.ItemIndex);
comm1.StopBits:=tstopbits(stopbits.ItemIndex);
comm1.Parity:=tparity(sendparty.ItemIndex);
try
comm1.StartComm;
except
raise exception.Create( '打开串口错误 ');
end;