|
님의 코딩을 보니 특별한 문제가 없었습니다.
그대로 복사해서 테스트했었는데...
에러없이 잘 동작하는군요
다른곳에서 문제가 발생하지는 않는지 함 찾아보시지요
혹시나해서 테스트코드를 붙여드립니다. (뭐 특별한것 없지만...)
그럼..
-----------테스트 소스------------------
@ unit1.h
........
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall TForm1::SetButtons(); //추가내용
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
@ unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#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)
{
for(int i=0;i<5;i++)
ListBox1->Items->Add("Item"+IntToStr(i+1));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Btn_SetButtonClick(TObject *Sender)
{
SetButtons();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetButtons()
{
bool SrcEmpty, DstEmpty;
SrcEmpty = (ListBox1->Items->Count == 0);
DstEmpty = (ListBox2->Items->Count == 0);
Button1->Enabled = (! SrcEmpty);
Button2->Enabled = (! SrcEmpty);
Button3->Enabled = (! DstEmpty);
Button4->Enabled = (! DstEmpty);
// Button1->Enabled = (ListBox1->Items->Count >0)?true:false;
// Button2->Enabled = Button1->Enabled;
// Button3->Enabled = (ListBox2->Items->Count >0)?true:false;
// Button4->Enabled = Button3->Enabled;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for (i = 0; i < ListBox1->Items->Count; i++)
if (ListBox1->Selected[i])
ListBox2->Items->AddObject(ListBox1->Items->Strings[i],
ListBox1->Items->Objects[i]);
for (i = ListBox1->Items->Count - 1; i >= 0; i--)
if (ListBox1->Selected[i])
ListBox1->Items->Delete(i);
SetButtons();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i;
for (i = 0; i < ListBox1->Items->Count; i++) {
ListBox2->Items->Add(ListBox1->Items->Strings[i]);
}
ListBox1->Clear();
SetButtons();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int i;
for (i = 0; i < ListBox2->Items->Count; i++)
if (ListBox2->Selected[i])
ListBox1->Items->AddObject(ListBox2->Items->Strings[i],
ListBox2->Items->Objects[i]);
for (i = ListBox2->Items->Count - 1; i >= 0; i--)
if (ListBox2->Selected[i])
ListBox2->Items->Delete(i);
SetButtons();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
int i;
for (i = 0; i < ListBox2->Items->Count; i++) {
ListBox1->Items->Add(ListBox2->Items->Strings[i]);
}
ListBox2->Clear();
SetButtons();
}
//---------------------------------------------------------------------------
빌더맨 님이 쓰신 글 :
: 안녕하십니까! 제가 이곳에 올리는 두번째 질문이네요
: 이번에는 ListBox를 활용하는 문제인거 같은데 이 소스 내용에서
: SetButton에 대한 내용을 빼고 실행하면 실행이 되는데
: SetButton에 대한 부분을 첨가 하고 실행 하면 에러가 뜨는데 도통 원인 파악을
: 못하겠습니다. SetButton의 소스 내용과 SetButton 활용 할 수 있는 방법좀
: 해결 할 수 있게 도와 주십시요. 오늘 하루도 수고 하십시요.
|