TList类问题!
我按照书上编了一个关于TList类使用的事件,但运行出现错误:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TList* pList =new TList();
String TheObject = "1234";
try
{
pList -> Add(TheObject);
ShowMessage("123");
pList -> Remove(TheObject);
}
__finally
{
delete pList;
}
}
运行错误为:
[C++ Error] Unit1.cpp(25): E2034 Cannot convert 'AnsiString' to 'void *'
[C++ Error] Unit1.cpp(25): E2342 Type mismatch in parameter 'Item' (wanted 'void *', got 'AnsiString')
求解啊!
[解决办法]
TList是一个对象列表,TStringList才是字符串列表。
TList只能添加一个对象指针,如:
TList *pList = new TList();try{ pList->Add(Button1); ShowMessage("123"); pList->Remove(Button1);}__finally{ delete pList;}
[解决办法]
TList* pList =new TList();
//String TheObject = "1234";
char TheObject[]= "1234";
try
{
pList -> Add(TheObject);
//ShowMessage("123");
ShowMessage( AnsiString((char *)pList->Items[0]) );
pList -> Remove(TheObject);
}
__finally
{
delete pList;
}
[解决办法]
TList 是非常好的类, 一直都在用它,功能也强。 常用的对象管理里面都用它了, 再加上 TThreadList 就非常棒了