请帮我看看吧 有一句不是很清楚 关于C++builder的
1.misclass.h:
#ifndef misclassH
#define misclassH
//---------------------------------------
enum TCCSortType {stName,stCompany};
//---------------------------------------
class TSearchSort : public TObject //定义排序的类
{
private:
TCCSortType FSortType;
void DoSort();
public:
void Sort(TCCSortType SortType);
}
//---------------------------------------
#endif
2.misclass.cpp
//---------------------------------------
#pragma hdrstop
#include "misclass.h"
#include "DataModule.h"
#include <vcl.h>
#include <db.hpp>
#include <registry.hpp>
#include <shellapi.h>
//---------------------------------------
void TSearchSort::DoSort() //选择排序方法,并设定索引
{
switch(FSortType)
{
case stName:
DataModule1->AddrTable->IndexName="Nameindex";
break;
case stCompany:
DataModule1->AddrTable->IndexName="Companyindex";
}
}
//---------------------------------------
void TSearchSort::Sort() //排序
{
FSortType=SortType;
DoSort();
}
//---------------------------------------
#pragma package(smart_init)
3.main.h
//---------------------------------------
#ifndef mainH
#define mainH
......
#include <Mask.hpp>
#include "misclass.h"
//---------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
......
private:
TSearchSort * FSearchSort;
// User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__property TSearchSort * SearchSort={read=FSearchSort,write=FSearchSort};
};
//---------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------
#endif
4.main.cpp
include "msiclass.h"
.......
void __fastcall TForm1::FormCreate(TObject *Sender)
{
FSearchSort=new TSearchSort;
}
......
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete FSearchSort;
}
//-----------------------
void __fastcall TForm1::namesortClick(TObject *Sender)
{
SearchSort->Sort(TCCSortType(dynamic_cast<TComponent*>(Sender)->Tag));
}
//---------------------------------------
最后一句的TCCSortType(dynamic_cast<TComponent*>(Sender)->Tag不明白是 什么意思
[解决办法]
dynamic_cast <TComponent*>(Sender)->Tag
是把sender转换成tcomponent型的。 再取tag的值(Int)类型。 假设tag=10;
再把tag的值转为TCCSortType(10)类型
[解决办法]
看一下帮助 TComponent::Tag 所以要转成TComponent类型的
dynamic_cast <TComponent*>(Sender)->Tag这句还是不要改成直接用控件名ControlName->Tag这种
看他的程序既然这样写 那很有可能其他控件的click事件是指向namesortClick的 不然他直接写namesort->Tag就好了 所以还是维持不要变的好