本人新手,打算自做一个类似串口助手的小软件,想用combobox控件来进行选择COMX口,进行通讯,可是每次开启comm的时候总是引发异常,,求指教,代码如下。。感谢额。
unit Form;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, SPComm;type
  TForm1 = class(TForm)
    Group_Communicate: TGroupBox;
    Box_Serial: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Box_Baud: TComboBox;
    Btn_Open: TBitBtn;
    Btn_Cancel: TBitBtn;
    Group_Receive: TGroupBox;
    L_R_Auto: TCheckBox;
    L_R_Hex: TCheckBox;
    Group_Send: TGroupBox;
    L_S_Hex: TCheckBox;
    L_S_Auto: TCheckBox;
    L_S_Clear: TCheckBox;
    Mem_Display: TMemo;
    Mem_Send: TMemo;
    Btn_Send: TBitBtn;
    L_Help: TLabel;
    Label4: TLabel;
    Label_Note: TLabel;
    Comm: TComm;
    Label5: TLabel;
    Label6: TLabel;
    Label3: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    procedure Btn_OpenClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Btn_OpenClick(Sender: TObject);
begin      if Box_Serial.ItemIndex = 0 then
        comm.CommName:='COM1'
      else if Box_Serial.ItemIndex = 1 then
        comm.CommName:='COM2'
      else if Box_Serial.ItemIndex = 2 then
        comm.CommName:='COM3'
      else if Box_Serial.ItemIndex = 3 then
        comm.CommName:='COM4';      {根据选项,设置串口}
      comm.BaudRate:=strtoint(Box_Baud.Text);
      {设置波特率}
      comm.StartComm;
      {开启串口}
end;end.