Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341672
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:43



小弟在做双机通信时,在编译的时候老是在这个地方:
YbCommDevice1->PortNo=Form2->ComboBox1->ItemIndex+1;
提示:
[C++ Error] Unit1.cpp(41): E2451 Undefined symbol 'YbCommDevice1'

我是不是在什么地方漏了什么控件?等侯回答。

原代码:
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
bool isfile;
int number=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
    //  ShowMessage(Form2->ShowModal());
     if(Form2->ShowModal()==6)
     {
          BitBtn1->Enabled=true;
     }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
      BitBtn1->Enabled=false;
      BitBtn2->Enabled=true;
      BitBtn3->Enabled=true;
      BitBtn5->Enabled=true;
      //////////////////

   YbCommDevice1->PortNo=Form2->ComboBox1->ItemIndex+1;

   switch(Form2->ComboBox2->ItemIndex)
   {
     case 0:YbCommDevice1->Baud=TYbCommDevice::br4800;break;
     case 1:YbCommDevice1->Baud=TYbCommDevice::br9600;break;
     case 2:YbCommDevice1->Baud=TYbCommDevice::br14400;break;
     case 3:YbCommDevice1->Baud=TYbCommDevice::br19200;break;
     case 4:YbCommDevice1->Baud=TYbCommDevice::br38400;break;
   }
   YbCommDevice1->ByteSize=Form2->ComboBox3->ItemIndex+5;

   switch(Form2->ComboBox4->ItemIndex)
   {
    case 0:YbCommDevice1->StopBits=TYbCommDevice::sbOneStopBit;break;
    case 1:YbCommDevice1->StopBits=TYbCommDevice::sbOne_5_StopBits;break;
    case 2:YbCommDevice1->StopBits=TYbCommDevice::sbTwoStopBit;break;
   }

   switch(Form2->ComboBox5->ItemIndex)
   {
    case 0:YbCommDevice1->Parity=TYbCommDevice::ptNoParity;break;
    case 1:YbCommDevice1->Parity=TYbCommDevice::ptOddParity;break;
    case 2:YbCommDevice1->Parity=TYbCommDevice::ptEvenParity;break;
    case 3:YbCommDevice1->Parity=TYbCommDevice::ptMarkParity;break;
   }
   try
   {
       YbCommDevice1->Active = true; //打开串口
   }
   catch(Exception &e)
   {
       ShowMessage(e.Message); //错误处理
   }
      ////////////////////
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
     BitBtn5->Enabled=false;
     BitBtn7->Enabled=true;
  if(OpenDialog1->Execute())
  {
     Memo1->Lines->Clear();
     Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
   }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{
      BitBtn8->Enabled=true;
      BitBtn5->Enabled=true;
      BitBtn7->Enabled=false;

   FILE *fp=fopen(OpenDialog1->FileName.c_str(),"rb");
   char ch;   number=0;
   while ((ch=fgetc(fp))!=EOF)
   {   number++;
      YbCommDevice1->Write(&ch,sizeof(char));
   }

   fclose(fp);
   isfile=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn6Click(TObject *Sender)
{
      Close();  
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
        YbCommDevice1->Active=false;
        BitBtn1->Enabled=true;
        BitBtn2->Enabled=false;  
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
     YbCommDevice1->Write(Edit1->Text.c_str(),Edit1->Text.Length());
     isfile=false;
}
//------------------------------------------------------------------

--------------------next---------------------

阅读(1144) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~