代码如下,
procedure SendData_Bit2;
var
 DataStr2:String;
 DataInt2:Integer;
 i:Integer;
 selLine:Integer;
 selStr:string;
begin
 DataStr2:=Form1.Edit2.Text;
 i:=StrToInt(DataStr2);   //String to Integer;
 selStr:=ComboBox2.Items[ComboBox2.ItemIndex];
 selLine:=ComboBox2.Items.Indexof(selStr);
 case selLine of
 0:
   begin
   DataInt2:=i+200;
   end;
 1:
  begin
  if i <11 then DataInt2:=i
  else if i > 11 then DataInt2 := (i div 100)+100;
  end;
 end;

 ViewStr:='';
 CommFlag:=True;
 input[1]:=DataInt2;
 if not Form1.Comm1.WriteCommData(@input[1],1)then
   begin
   CommFlag:=False;
   end;
 ViewStr:='Send'+''+DataStr2;
 Form1.Memo1.Lines.Add(ViewStr);
 if not CommFlag then messagedlg('sending falied' ,mterror,[mbyes],0);
end;

解决方案 »

  1.   

    请问,红色部分的编写有错误么?
    为什么老是提醒ComboBox2是undeclared identifier?
      

  2.   

    procedure SendData_Bit2; 
    不是
    procedure TForm1.SendData_Bit2;你这是一个独立的过程,不是你的窗口类的一个方法,ComboBox2是你的窗体类的成员。你在独立的过程里面去找一个ComboBox2当然找不到
      

  3.   

    你写的方法是全局的方法;应该把窗体的名称加载到Combobox2前面。
    比如此时你的窗体为Form1,则把Combobox2修改为Form1.Combobox2就不会出问题。