線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1259
推到 Plurk!
推到 Facebook!

'ItemIndex' is not a member of 'TRadioButton' 出錯

答題得分者是:ikk
stelliver
一般會員


發表:2
回覆:0
積分:0
註冊:2009-02-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-02-25 02:00:04 IP:118.161.xxx.xxx 訂閱
最近剛接觸BCB,這個程式碼是照課本上打下來的但是一直出現
[C Error] Unit1.cpp(56): E2316 'ItemIndex' is not a member of 'TRadioButton'
拜請過GOOGLE大神了,還是無解。
幫忙解惑一下,感恩



#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE hComm;
boolean DTRState;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
String Temp;
char *SendData;
int in;
unsigned long lrc,BS;
if (hComm==0) return;
Temp = mSend->Text;
SendData= Temp.c_str();
BS =Temp.Length();
WriteFile(hComm,SendData,BS,&lrc,NULL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
String Temp;
char inbuff[1024];
DWORD nBytesRead,dwEvent,dwError;
COMSTAT cs;
ClearCommError(hComm,&dwError,&cs);
if (cs.cbInQue > sizeof(inbuff))
{
PurgeComm(hComm,PURGE_RXCLEAR);
return;
}
ReadFile(hComm,inbuff,cs.cbInQue,&nBytesRead,NULL);
inbuff[cs.cbInQue]='\0';
mReceive->Text=inbuff;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *ComNo;
DCB dcb;
String Temp;
Temp="COM" IntToStr(rdCOM->ItemIndex 1); ///這行出問題
//轉換指標型態
ComNo=Temp.c_str();
hComm=CreateFile(ComNo,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if (hComm==INVALID_HANDLE_VALUE)
{
MessageBox(0,"開啟通訊阜錯誤!!","Comm Error",MB_OK);
return;
}
GetCommState(hComm,&dcb);
dcb.BaudRate= CBR_9600;
dcb.ByteSize=8;
dcb.Parity=NOPARITY;
dcb.StopBits=ONESTOPBIT;
if (!SetCommState(hComm,&dcb) )
{ MessageBox(0,"開啟通訊阜錯誤!!","Comm Error",MB_OK);
CloseHandle(hComm);
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (hComm !=INVALID_HANDLE_VALUE) CloseHandle(hComm);
exit(EXIT_SUCCESS);
}

補上.h宣告
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include Classes.hpp>
#include Controls.hpp>
#include StdCtrls.hpp>
#include Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRadioButton *rdCOM;
TRadioButton *rdCOM2;
TMemo *mSend;
TMemo *mReceive;
TButton *Button1;
TButton *Button2;
TButton *Button3;
TButton *Button4;
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

因為是新手又是自學,後來發現是元件選錯造成的。要選用radiogroup 而不是radiobutton
編輯記錄
stelliver 重新編輯於 2009-02-25 16:52:53, 註解 無‧
stelliver 重新編輯於 2009-02-25 16:54:18, 註解 無‧
stelliver 重新編輯於 2009-02-25 18:19:42, 註解 無‧
ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-02-25 09:14:29 IP:163.28.xxx.xxx 訂閱
從error message看來就是,rdCOM是個TRadioButton,
而TRadioButton 沒有ItemIndex這個member,
你可能要把 .h 的宣告部份也post上來才了解問題出在哪....

不過我想rdCOM應該是個TRadioGroup才對....
------
FPGA驗證, FPGA開發平台, http://smims.com
系統時間:2024-04-19 21:24:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!