c++ - 迭代结构;在 RichEdit 框中轻松显示结构字段和值

标签 c++ user-interface struct richedit c++builder-5

有没有更简单的方法在 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/

相关文章:

c++ - 使用 .txt 文件中的数据填充数组,但将不在文本文件中的数字添加到数组

windows - 如何为 Java SWT 应用程序实现类似 Google-chrome 的标题栏

pointers - 当字段是指向 x 的指针时,使用反射设置结构字段的值

c++ - 我怎样才能声明一个结构?

ios - Swift:在协议(protocol)中使用未定义的函数?

c++ - 如何从 NTFS 索引号获取文件路径?

c++ - libvncserver/libvncclient websocket支持(至vSphere)?

c++ - 不能使用隐式链接的 .dll 中的类

c++ - 选择单元格时,更改 QTableView 中图标的颜色突出显示

c# - 在页面之间导航时 Windows 应用商店应用程序暂停