⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basemain.cpp.bak

📁 符合移动协议的见空系统,很有使用简直,希望多下载
💻 BAK
📖 第 1 页 / 共 5 页
字号:
          gp_ComGrid[i].pCbx->ItemIndex = -1;
      }
      else if(gp_ComGrid[i].EditStyle == 2)
      {
        gp_ComGrid[i].pShp->Brush->Color = clGreen;
      }
    }
    TabbedNotebook1->PageIndex = 0;
    return;
  }
  m_bWays = false;
  InitObjectGroup();

  GridCleanItems();
  for(int i=0; i<MAX_OBJECTID; i++)
  {
    if(gObjectValue[i].bUsed == 0 || gp_ComGrid[i].bUsed == 0)
      continue;
    gp_ComGrid[i].bUsed = 0;
    gp_ComGrid[i].pCb->Left = -200;
    gp_ComGrid[i].pCb->Checked = false;
    gp_ComGrid[i].pLb->Left = -200;
    gp_ComGrid[i].pLb->TabStop = false;
    if(gp_ComGrid[i].EditStyle == 0)
    {
      gp_ComGrid[i].pEd->Left = -200;
      gp_ComGrid[i].pEd->Text = "";
      //gp_ComGrid[i].pEd->TabStop = false;
    }
    else if(gp_ComGrid[i].EditStyle == 1)
    {
      gp_ComGrid[i].pCbx->Left = -200;
      if(i>=0x0200 && i<=0x02FF)
        gp_ComGrid[i].pCbx->ItemIndex = 0;
      else
        gp_ComGrid[i].pCbx->ItemIndex = -1;
      //gp_ComGrid[i].pCbx->TabStop = false;
    }
    else if(gp_ComGrid[i].EditStyle == 2)
    {
      gp_ComGrid[i].pShp->Left = -200;
      gp_ComGrid[i].pShp->Brush->Color = clGreen;
    }
  }
  TabbedNotebook1->PageIndex = 0;
  RefreshScreen();
}

void __fastcall TForm1::GridCleanItems()
{
  TcxGridTableView *TblView;
  for(int i=0; i<mptvVCL->Count; i++)
  {
    TblView = ((TcxGridTableView*)mptvVCL->Items[i]);
    TblView->BeginUpdate();
    try
    {
      TblView->ClearItems();
    }
    __finally
    {
      TblView->EndUpdate();
    }
  }
}



void __fastcall TForm1::FillPackData(INT16 iObjectID, INT8U *ptLen, INT8U *ptTemp)
{
	INT8U 	i;
	INT16U 	mObjectID, code;
  INT8U  szKey[100];
  char buf[100], tmpBuf[100];
  AnsiString EditBuf;
  memset(buf, 0, 100);

	mObjectID = iObjectID;
	Swap_INT16U(&mObjectID);

  //str_cpy((INT8U*)gObjectValue[mObjectID].ptVarible, ptVariable, gObjectValue[mObjectID].Object_Length);

  if(mObjectID == 0x04A2) return;
  
  if(gObjectValue[mObjectID].bSingle)
  {
    if(mObjectID == 0x0002 || mObjectID == 0x0003 || mObjectID == 0x0141
       || mObjectID == 0x0142 || mObjectID == 0x0166)
      *ptTemp = gp_ComGrid[mObjectID].pCbx->ItemIndex + 1;
    else
      *ptTemp = gp_ComGrid[mObjectID].pCbx->ItemIndex;
  }
  else if(mObjectID == 0x0101)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    ForceAlign(buf, 8);
    Str_2_INT8U(buf,szKey,8);
    Reverse_INT8U(szKey, 4);
    str_cpy(ptTemp, szKey, 4);
  }
  else if(mObjectID == 0x0102)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    *ptTemp = strtol(buf, NULL, 16);
  }
  else if(mObjectID == 0x0130)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    int i = 0;

    while(ExtractColumn(buf,i, tmpBuf, "."))
    {
      szKey[i] = strtol(tmpBuf, NULL, 10);
      i++;
    }
    str_cpy(ptTemp, szKey, 4);
  }
  else if(mObjectID == 0x0150)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    CleanHeadTailSpace(buf);
    char *p1 = buf;
    while(*p1)
    {
      if(*p1 == 0x20 || *p1 == ':' || *p1 == '-')
        strcpy(p1, p1+1);
      else
        p1++;
    }
    *p1 = 0;
    ForceAlign(buf, 14);
    Str_2_INT8U(buf, szKey,14);
    str_cpy(ptTemp, szKey, 7);
  }
  else if(mObjectID == 0x001F)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    /*strcpy(buf, EditBuf.c_str());
    memset(szKey, 0x00, 100);
    stringtoINT8U(buf, szKey);*/
    StrFloatToHex(EditBuf, szKey);
    str_cpy(ptTemp, szKey, 4);
  }
  else if(*ptLen==20)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());

    if(mObjectID == 0x0007 || mObjectID == 0x0008)
    {
      CleanHeadTailSpace(buf);
      strstr_rpl(buf, "东经", "E");
      strstr_rpl(buf, "西经", "W");
      strstr_rpl(buf, "北纬", "N");
      strstr_rpl(buf, "南纬", "S");
    }
    memset(szKey, 0x00, 100);
    stringtoINT8U(buf, szKey);
    str_cpy(ptTemp, szKey, 20);
  }
  else if(*ptLen == 1)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    CleanHeadTailSpace(buf);
    if(gObjectValue[mObjectID].bSign == 1)
    {
      if(buf[0]== '-')
        code = -strtol(buf+1, NULL, 10);
      else
        code = strtol(buf, NULL, 10);
      *ptTemp = code;
    }
    else if(gObjectValue[mObjectID].bZoom == 1)
    {
      EditBuf = gp_ComGrid[mObjectID].pEd->Text;
      strcpy(buf, EditBuf.c_str());
      double x;
      x = strtod(buf, NULL);
      EditBuf = FormatFloat("#.#", x);
      x = strtod(EditBuf.c_str(), NULL);
      *ptTemp = (INT8U)(x*10);
    }
    else
      *ptTemp = strtol(buf, NULL, 10);
  }
  else if(*ptLen == 0x02)
  {
    EditBuf = gp_ComGrid[mObjectID].pEd->Text;
    strcpy(buf, EditBuf.c_str());
    code = strtol(buf, NULL, 10);
    Swap_INT16U(&code);
    INT16U_2_INT8Upt(szKey, code);
    str_cpy(ptTemp, szKey, 2);
  }
}

void __fastcall TForm1::InitControlObject()
{
  char Buf[100], Temp[100];
  INT8U iGroup, iObjectId;
  for(int i=0; i<MAX_OBJECTID; i++)
  {
		sprintf(Buf, "%04X", i);
		CPtrMap t(Buf, ""), *tmp;
    if(gObjectValue[i].bUsed == 0)
		  continue;
    iGroup = i>>8;
    iObjectId = i&0x00FF;

		gp_ComGrid[i].SizeLen = gObjectValue[i].Object_Length;
		gp_ComGrid[i].bZoom = gObjectValue[i].bZoom;
		gp_ComGrid[i].bSign = gObjectValue[i].bSign;

    gp_ComGrid[i].SetParent((TcxGrid*)mpcxVCL->Items[iGroup]);
    if(gObjectValue[i].bSingle)
    {
      gp_ComGrid[i].BuildComb();
	    AddDropListItem(gp_ComGrid[i].pCbx, iGroup,iObjectId);
      gp_ComGrid[i].pCbx->Tag = 1000+i*2+1;
      gp_ComGrid[i].pCbx->TabStop = false;
      gp_ComGrid[i].pCbx->OnKeyPress = MaskKeyPress;
      gp_ComGrid[i].pCbx->OnSelect = ChangeSelectBox;
      gp_ComGrid[i].pCbx->OnChange = ChangeSelectBox;
    }
    else
    {
      if(iGroup==3)
	  	  gp_ComGrid[i].BuildShape();
      else
      {
        gp_ComGrid[i].BuildEdit();
        WriteEidtMask(i);
        gp_ComGrid[i].pEd->Tag = 1000+i*2+1;
        gp_ComGrid[i].pEd->TabStop = false;
        gp_ComGrid[i].pEd->OnKeyPress = MaskKeyPress;
        gp_ComGrid[i].pEd->ShowHint = true;
        AddHintShow(i);
      }
      if(gObjectValue[i].CmdNo == 0)
        gp_ComGrid[i].pEd->ReadOnly = true;
    }
    gp_ComGrid[i].pLb->TabStop = false;
		gp_ComGrid[i].pLb->Text =(char*)gObjectValue[i].ObjectName;
    gp_ComGrid[i].pCb->Tag = 1000+i*2;
    gp_ComGrid[i].pCb->OnKeyPress = MaskKeyPress;
    INT16U code = i;
    Swap_INT16U(&code);
		gp_ComGrid[i].ObjectID = code;
  }
}


void __fastcall TForm1::AddHintShow(int i)
{
  if(i==0x0014 || i==0x0016 || i==0x0017 || i==0x0134)
    gp_ComGrid[i].pEd->Hint = "单位为秒";
  else if(i==0x0015)
    gp_ComGrid[i].pEd->Hint = "单位为毫秒";
  else if(i==0x0019)
    gp_ComGrid[i].pEd->Hint = "表示升级进度的百分比";
  else if(i==0x0130 || i==0x0150)
    gp_ComGrid[i].pEd->Hint = "输入格式为:192.168.0.1";
  if((i>=0x0440 && i<=0x0449) || i==0x0504 || i==0x0505 || i==0x0512 || i==0x0513
     || i==0x0518 || i==0x0519 || i==0x051E || i==0x051F || i==0x0524 || i==0x0525)
    gp_ComGrid[i].pEd->Hint = "单位为dB";
  else if((i>=0x044A && i<=0x044D) || i==0x0450 || i==0x046B || i==0x0471 ||
      i==0x0477 || i==0x047D || i==0x0486 || i==0x0515 || i==0x051B || i==0x0521 ||
      i==0x0527 || i==0x0533 ||(i>=0x0560 && i<=0x0563))
    gp_ComGrid[i].pEd->Hint = "比例为10";
  else if(i==0x0451 || i== 0x0501)
    gp_ComGrid[i].pEd->Hint = "单位为℃";
  else if((i>=0x0453 && i<=0x0457) || (i>=0x0466 && i<=0x047C) || (i>=0x050D && i<=0x0517) ||
      i==0x0502 || i==0x0503 || i==0x050B)
    gp_ComGrid[i].pEd->Hint = "单位为dBm";
  else if((i>=0x0480 && i<=0x049F) || (i>=0x0530 && i<=0x053F) || i==0x0550 || i==0x0551
      || (i>=0x0612 && i<=0x0623))
    gp_ComGrid[i].pEd->Hint = "单位为dBm,比例为10";
  else if(i==0x0150 || i==0x0601)
    gp_ComGrid[i].pEd->Hint = "输入格式为:2005-01-18 15:38:44";
  else if(i == 0x0602)
    gp_ComGrid[i].pEd->Hint = "单位为分";
}

void AddDropListItem(TComboBox *pCmb, int groupid, int objectid)
{
  pCmb->ItemIndex = -1;
  if(groupid == 0)
  {
    if(objectid == 0x09 || objectid == 0x0A)
    {
      pCmb->Items->Add("关闭");
      pCmb->Items->Add("打开");
    }
    else if(objectid == 0x0B)
    {
      pCmb->Items->Add("正常");
      pCmb->Items->Add("失步");
    }
    else if(objectid == 0x23 || objectid == 0x24)
    {
      pCmb->Items->Add("强关模式");
      pCmb->Items->Add("正常开关模式");
      pCmb->Items->Add("上开下关模式");
      pCmb->Items->Add("下开上关模式");
    }
    else if(objectid == 0x2D)
    {
      pCmb->Items->Add("外部产生");
      pCmb->Items->Add("自已产生");
    }
    else if(objectid == 0x2E)
    {
      pCmb->Items->Add("仪器同步");
      pCmb->Items->Add("检测同步");
    }
    else
    {
      pCmb->Items->Add("正常");
      pCmb->Items->Add("故障");
    }
  }
  else if(groupid == 0x02)
  {
    if(objectid == 0x01 || objectid == 0x02)
    {
      pCmb->Items->Add("正常");
      pCmb->Items->Add("故障");
    }
    else
    {
      pCmb->Items->Add("正常");
      pCmb->Items->Add("失步");
    }
  }
}



void __fastcall TForm1::DealReceiveObject()
{
  INT8U *ptPosLen;
 	ptPosLen = &gReceivePackData.depack_data[PRTCL_POS_VARIABLE];
  str_cpy(mp_Object,ptPosLen+5, *ptPosLen-5);
  mp_Object += (*ptPosLen - 5);
  m_iCount += (*ptPosLen - 5);
}

//---------------------------------------------------------------------------

void __fastcall TForm1::WriteEidtMask(INT16U iObjectId)
{
  if(iObjectId == 0x0101)
  {
    gp_ComGrid[iObjectId].pEd->MaxLength = 8;
    gp_ComGrid[iObjectId].pEd->CharCase = ecUpperCase;
  }
  else if(iObjectId == 0x0102)
  {
    gp_ComGrid[iObjectId].pEd->MaxLength = 2;
    gp_ComGrid[iObjectId].pEd->CharCase = ecUpperCase;
  }
  else if(iObjectId == 0x001F)
  {
    gp_ComGrid[iObjectId].pEd->MaxLength = gObjectValue[iObjectId].Object_Length;
  }
  else if(gObjectValue[iObjectId].Object_Length >= 20)
    gp_ComGrid[iObjectId].pEd->MaxLength = gObjectValue[iObjectId].Object_Length;
  else if(iObjectId == 0x0150 || iObjectId == 0x0601)
  {
    gp_ComGrid[iObjectId].pEd->MaxLength = 19;
  }
  else if(iObjectId>=0x04FC && iObjectId<=0x04FF)
  {
    gp_ComGrid[iObjectId].pEd->MaxLength = 17;
  }
  else if(gp_ComGrid[iObjectId].SizeLen == 2)
  {
    if(gp_ComGrid[iObjectId].bSign == 1)
      gp_ComGrid[iObjectId].pEd->MaxLength = 6;
    else
      gp_ComGrid[iObjectId].pEd->MaxLength = 5;
  }
  else if(gp_ComGrid[iObjectId].SizeLen == 1)
  {
    if(gp_ComGrid[iObjectId].bSign)
      gp_ComGrid[iObjectId].pEd->MaxLength = 4;
    else if(gp_ComGrid[iObjectId].bZoom)
      gp_ComGrid[iObjectId].pEd->MaxLength = 4;
    else
      gp_ComGrid[iObjectId].pEd->MaxLength = 3;
  }
  if(iObjectId<0x0500)
    gp_ComGrid[iObjectId].pEd->OnExit = ShowMessageBox;
  gp_ComGrid[iObjectId].pEd->OnStartDock = StartDock;
  gp_ComGrid[iObjectId].pEd->OnChange = ChangeSelectBox;
  gp_ComGrid[iObjectId].pEd->OnEndDock = EndDock;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MaskKeyPress(TObject *Sender, char &Key)
{
  INT16U  uiTab, code = 0, iStart;
  INT8U iGroup;
  if (Key==13)
  {
    if(Sender->ClassNameIs("TCheckBox"))
    {
      uiTab = ((TCheckBox*)Sender)->Tag;
      if(uiTab>=1000)
      {
        if(gp_ComGrid[(uiTab-1000)/2].EditStyle == 0)
          ActiveControl = gp_ComGrid[(uiTab - 1000)/2].pEd;
        else if(gp_ComGrid[(uiTab-1000)/2].EditStyle == 1)
          ActiveControl = gp_ComGrid[(uiTab - 1000)/2].pCbx;
      }
    }
    else if(Sender->ClassNameIs("TMaskEdit") || Sender->ClassNameIs("TComboBox"))
    {
      if(Sender->ClassNameIs("TMaskEdit"))
        uiTab = ((TMaskEdit*)Sender)->Tag;
      else
        uiTab = ((TComboBox*)Sender)->Tag;
      if(uiTab>=1000)
      {
        code = (uiTab - 1000)/2;
        iGroup = ((uiTab - 1000)/2)>>8;
        iStart = code+1;
        while(gp_ComGrid[iStart].bUsed==0)
        {
          if((iStart>>8)>iGroup || iStart>=MAX_OBJECTID)
          {
            iStart = iGroup<<8;
            continue;
          }
          iStart++;
        }
        code = iStart;
        if(gp_ComGrid[code].EditStyle == 0)
          ActiveControl = gp_ComGrid[code].pEd;
        else if(gp_ComGrid[code].EditStyle == 1)
          ActiveControl = gp_ComGrid[code].pCbx;
      }
    }
  }
}

void __fastcall TForm1::StartDock(TObject *Sender, TDragDockObject *&DragObject)
{
  SelectNext(ActiveControl,true,true);
}

void __fastcall TForm1::EndDock(TObject *Sender, TObject *Target, int X, int Y)
{
  SelectNext(ActiveControl,true,true);
}

void __fastcall TForm1::ShowErrorMsg(TObject *Sender, AnsiString MsgText)
{
  Form2->SetMsgText(MsgText);
  Form2->ShowModal();
  ((TMaskEdit*)Sender)->Text = "";
}

void __fastcall TForm1::ShowMessageBox(TObject *Sender)
{
  AnsiString dtText;
  char *p1 = NULL;
  INT32U  uiTab, code;

  dtText = ((TMaskEdit*)Sender)->Text;
  p1 = dtText.c_str();
  uiTab = ((TMaskEdit*)Sender)->Tag;
  code = (uiTab - 1000)/2;
  if(code == 0x0130)
  {
    if(MarkCount(p1, ".")!=3  || !Is_WholeNumber(p1, 0, 1))
    {
        ShowErrorMsg(Sender, "输入错误: 请严格按照\"192.168.000.012\"格式输入IP地址");
        goto Error1;
    }
    while(*p1)
    {
      if(*p1>='0' && *p1<='9')
        p1++;
      else if(*p1=='.')
      {
        p1++;
        if(!(*p1>='0' && *p1<='9'))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -