首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

大家帮小弟我看下有关问题代码:运行出现异常“Menu inserted twice”,不知哪里冲突了

2012-02-26 
大家帮我看下问题代码:运行出现错误“Menuinsertedtwice”,不知哪里冲突了大家帮我看下问题代码:编译时没有

大家帮我看下问题代码:运行出现错误“Menu inserted twice”,不知哪里冲突了
大家帮我看下问题代码:编译时没有问题但运行时有一个菜单项N11Clic(Intermediary Device)这个按钮有问题,一点它无论是左边的树形结构菜单还是主菜单栏下的Intermediary Deviced的这个按钮,“Menu inserted twice”,现在我把有问题的代码贴出来大家帮我看一下哪里冲突了。

[code=C/C++][/code]
void __fastcall TForm1::N11Click(TObject *Sender)
{
  TTreeNode *CurrNode;

  for(int i=0; i<TreeView1->Items->Count; i++)
  {
  CurrNode = TreeView1->Items->Item[i];
  if((CurrNode->Level == 1)&&(CurrNode->Text == "Intermediary Device"))
  {
  CurrNode->Selected = true;  
  }
  }
}

[code=C/C++][/code]
if(Node->Text == "Intermediary Device")
  {
  Image1->Visible = false;
  Label1->Visible = true;
  Label3->Visible = true;
  Label4->Visible = true;
  Label5->Visible = true;
  Label6->Visible = true;
  Label7->Visible = true;
  Label8->Visible = true;
  Label9->Visible = true;
  ToolBar2->Visible = true;
  ToolButton10->Enabled = true;
  ToolButton10->Caption = "Add";
  ToolButton11->Enabled = true;
  ToolButton12->Enabled = true;
  ToolButton13->Enabled = true;
  ComboBox1->Visible = true;
  DBGrid1->Height = 417;
  DBGrid1->Visible = true;
  Label10->Visible = false;
  Memo1->Visible = false;
  Button1->Visible = false;
  Button2->Visible = false;
  Button3->Visible = false;
  Button4->Visible = false;

  PopupMenu1->Items->Clear();
  for(i=0; i<8; i++)
  {
  NewItem[i] = new TMenuItem(PopupMenu1); // create the new item
  PopupMenu1->Items->Add(NewItem[i]);
  NewItem[i]->Caption = Mid_PopMenu[i];
  NewItem[i]->Tag = i;
  }
  for(i=8; i<10; i++)
  {
  NewItem[i] = new TMenuItem(PopupMenu1); // create the new item
  NewItem[7]->Add(NewItem[i]);
  NewItem[i]->Caption = Mid_PopMenu[i];
  NewItem[i]->Tag = i;
  }
  NewItem[0]->OnClick = ToolButton10Click; //增加
  NewItem[1]->OnClick = ToolButton11Click; //删除
  NewItem[2]->OnClick = ToolButton12Click; //修改
  NewItem[3]->OnClick = N39Click; //查找
  NewItem[4]->OnClick = PopPingClick; //测试连通
  NewItem[5]->OnClick = PopAddrSetupClick; //地址设置
  NewItem[6]->OnClick = PopICCardOperateClick; //IC卡操作
  NewItem[7]->OnClick = NULL;//PopDoorResetPassClick; //复位密码
  NewItem[8]->OnClick = PopDoorResetPass1Click; //复位工程密码
  NewItem[9]->OnClick = PopDoorResetPass2Click; //复位开锁密码
  DBGrid1->PopupMenu = PopupMenu1;

  Label1->Caption = "Intermediary Device:";
  Form1->ArrayType="TerminalType,Building,Unit,Storey,Room,TNum";
  ComboBox1->Clear();
  ComboBox1->Items->Add("All");
  ComboBox1->Items->Add("Door Entrance Unit");
  ComboBox1->Items->Add("Villa Door Entrance Unit");


  ComboBox1->Items->Add("Community Entrance Unit");
  ComboBox1->Items->Add("Management Server");
  ComboBox1->ItemIndex = 0;
  DBGrid1->Columns->Clear();
  for(i=0; i<6; i++)
  DBGrid1->Columns->Add();
  for(i=0; i<6; i++)
  {
  DBGrid1->Columns->Items[i]->FieldName = Mid_FieldName[i];
  DBGrid1->Columns->Items[i]->Title->Caption = Mid_Title[i];
  DBGrid1->Columns->Items[i]->Alignment = taCenter;
  DBGrid1->Columns->Items[i]->Title->Alignment = taCenter;
  }
  DBGrid1->DataSource = DataModule35->DataSource16;
  DataModule35->Query6->Close();
  DataModule35->Query6->SQL->Clear();
  DataModule35->Query6->SQL->Add("Select " + CdtCol + " from cdtinfo");
  DataModule35->Query6->SQL->Add(" where "+WhereCol2);
  DataModule35->Query6->SQL->Add("order by "+Form1->ArrayType);
  DataModule35->Query6->Parameters->ParamByName("ComputerNo")->Value=Form1->ComputerNo;
  DataModule35->Query6->Open();
  Mid_Records=DataModule35->Query6->RecordCount;
  Label5->Caption = IntToStr(Mid_Records);
  DataModule35->LoginQuery->Close();
  DataModule35->LoginQuery->SQL->Clear();
  DataModule35->LoginQuery->SQL->Add("Select CustNo from cdtinfo");
  DataModule35->LoginQuery->SQL->Add(" where "+WhereCol2);
  DataModule35->LoginQuery->SQL->Add("and LoginC = :cLoginC");
  DataModule35->LoginQuery->Parameters->ParamByName("cLoginC")->Value=false;
  DataModule35->LoginQuery->Parameters->ParamByName("ComputerNo")->Value=Form1->ComputerNo;
  DataModule35->LoginQuery->Open();
  Mid_NotConn = DataModule35->LoginQuery->RecordCount;
  Label9->Caption=IntToStr(Mid_NotConn);
  Label7->Caption=IntToStr(Mid_Records - Mid_NotConn);
  return;
  }

[解决办法]
上面的错了,这么改

C/C++ code
/*for(i=0; i<8; i++){NewItem[i] = new TMenuItem(PopupMenu1); // create the new itemPopupMenu1->Items->Add(NewItem[i]);NewItem[i]->Caption = Mid_PopMenu[i];NewItem[i]->Tag = i;}for(i=8; i<10; i++){NewItem[i] = new TMenuItem(PopupMenu1); // create the new itemNewItem[7]->Add(NewItem[i]);NewItem[i]->Caption = Mid_PopMenu[i];NewItem[i]->Tag = i;}*/for(i=0; i<8; i++){NewItem[i] = new TMenuItem(PopupMenu1); // create the new item//PopupMenu1->Items->Add(NewItem[i]);NewItem[i]->Caption = Mid_PopMenu[i];NewItem[i]->Tag = i;}for(i=8; i<10; i++){//NewItem[i] = new TMenuItem(PopupMenu1); // create the new itemNewItem[i] = new TMenuItem(NewItem[7]); // create the new subitem//NewItem[7]->Add(NewItem[i]);NewItem[i]->Caption = Mid_PopMenu[i];NewItem[i]->Tag = i;} 

热点排行