有没有更简单的方法在 RichEdit
控件中显示 struct
字段及其对应的值?
这就是我现在正在做的事情:
AnsiString s;
s = IntToStr(wfc.fontColor);
RichEdit1->Lines->Append(s);
等等……
有没有比必须单独调用每个人更简单的方法?我想读取一个二进制文件,然后在 RichEdit
控件中为我正在构建的一个小实用程序显示相应的结构,但没有找到其他方法。我已经知道如何读取二进制文件并将值读入 struct
。
最佳答案
BOOST_FUSION_ADAPT_STRUCT
似乎很适合这里。例如:
// Your existing struct
struct Foo
{
int i;
bool j;
char k[100];
};
// Generate an adapter allowing to view "Foo" as a Boost.Fusion sequence
BOOST_FUSION_ADAPT_STRUCT(
Foo,
(int, i)
(bool, j)
(char, k[100])
)
// The action we will call on each member of Foo
struct AppendToTextBox
{
AppendToTextBox(RichEditControl& Ctrl) : m_Ctrl(Ctrl){}
template<typename T>
void operator()(T& t)const
{
m_Ctrl.Lines.Append(boost::lexical_cast<std::string>(t));
}
RichEditControl& m_Ctrl;
};
// Usage:
void FillTextBox(Foo& F, RichEditControl& Ctrl)
{
boost::fusion::for_each(F, AppendToTextBox(Ctrl));
}
关于c++ - 迭代结构;在 RichEdit 框中轻松显示结构字段和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1878285/