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

如何將A Table所動態產生的CheckBox,將被選取的項目存到B Table

尚未結案
maxhuang
一般會員


發表:2
回覆:1
積分:0
註冊:2004-10-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-08 19:40:11 IP:61.229.xxx.xxx 未訂閱
一開始就利用資料庫裡的A Table資料產生一串CheckBox,程式碼如下:
__fastcall TForm5::TForm5(TComponent* Owner)
        : TForm(Owner)
{
        int ItemTop,ItemLeft,ArrayCheck;
        ItemTop = 20;
        ItemLeft = 244;
        ArrayCheck = 0;
        while(!ADODataSet1->Eof)
        {
                TCheckBox *CheckBox1;
                CheckBox1 = new TCheckBox(this);
                CheckBox1->Parent = this;
                CheckBox1->Top=ItemTop;
                CheckBox1->Left=ItemLeft;
                CheckBox1->Width=180;
                CheckBox1->Caption=ADODataSet1->FieldByName("c_name")->AsString;
                CheckBox1->Name=ADODataSet1->FieldByName("product_no")->AsString;
                ItemTop =30;                    ADODataSet1->Next();
        }
        ADODataSet1->First();
}
但問題在於如何將這些CheckBox中,將有被Checked的項目,存到B Table的product_no,c_name中 當然在存到B Table之前會把B Table重新清空用command就可以做到. 但問題在於如何將這些被選取的項目存回去呢? 小弟實在想不出有什麼方法,可否請各位高手為我想想辦法,救救命!
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-10 23:29:58 IP:211.22.xxx.xxx 未訂閱
宣告一個TList串列結構,把每一個新增的CheckBox指標存入,利用TList的Count及Item取出每一個新增的CheckBox指標內容! ----------------------------------------------- Creation is the fundation of promotion.
maxhuang
一般會員


發表:2
回覆:1
積分:0
註冊:2004-10-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-11 13:59:39 IP:61.222.xxx.xxx 未訂閱
Dear Stallion: 感謝您我回應,但小弟對您所說的方法看不太懂, 能否請您給我更具體的解答, 例如,我要如何做才能把每一個新增的CheckBox指標存入Tlist??
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-11 19:32:27 IP:211.22.xxx.xxx 未訂閱
我已測試過!    //header    #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include  #include #include #include <Forms.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components void __fastcall FormCreate(TObject *Sender); private: // User declarations TList *aList; //這裡加個串列結構指標 public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif //----code------------------ //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int ItemTop,ItemLeft,ArrayCheck,i; TCheckBox *CheckBox1,*TempBox; AnsiString Title,Cap; ItemTop = 20; ItemLeft = 244; aList = new TList; //起始串列結構 i = 0; while( i < 5 ) { CheckBox1 = new TCheckBox(this); CheckBox1->Parent = this; CheckBox1->Top=ItemTop; CheckBox1->Left=ItemLeft; CheckBox1->Width=180; CheckBox1->Caption= "NUMBER" AnsiString(i 1); CheckBox1->Name="NUMBER" AnsiString(i 1); aList->Add(CheckBox1); ItemTop =100; i ; } i = aList->Count - 1; while ( i > 0 ) { TempBox = ( TCheckBox * )aList->Items[i]; ShowMessage( TempBox->Caption); //TempBox->Free(); //不用時這邊要放掉,免得記憶體吃光光! --i; } aList->Free(); //清理串列結構 } //--------------------------------------------------------------------------- ----------------------------------------------- Creation is the fundation of promotion. 發表人 - stallion 於 2005/05/11 19:34:21 發表人 - stallion 於 2005/05/11 19:35:17
shair1221
一般會員


發表:1
回覆:2
積分:0
註冊:2005-05-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-05-13 10:01:03 IP:61.61.xxx.xxx 未訂閱
引言: i = aList->Count - 1; while ( i > 0 ) { TempBox = ( TCheckBox * )aList->Items[i]; ShowMessage( TempBox->Caption); //TempBox->Free(); //不用時這邊要放掉,免得記憶體吃光光! --i; } aList->Free(); //清理串列結構 } //---------------------------------------------------------------------------
最後一個while迴圈有些問題, 會漏掉aList->Items[0]。 應該把i = aList->Count - 1;省掉 然後while迴圈改成 while (i) { TempBox = ( TCheckBox * )aList->Items[--i]; ShowMessage( TempBox->Caption); TempBox->Free(); } 這樣就ok了。 發表人 - shair1221 於 2005/05/13 10:04:33
系統時間:2024-04-29 3:55:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!