Alex Rivera | Logout

Iterate Over Struct; Easily Display Struct Fields And Values In a RichEdit Box

Asked 2009-12-10T02:26:12.770
13

Is there an easier way to display the struct fields and their corresponding values in RichEdit control?

This is what I am doing now:

AnsiString s;

s = IntToStr(wfc.fontColor);
RichEdit1->Lines->Append(s);

etc...

Is there an easier way than having to individually call each one? I want to read a binary file and then display the corresponding structure in a RichEdit control for a small utility I am building and have found no other way. I know how to read binary files and read the values into the struct already.

Edit
Report

1 Answer

1

I suggest creating templated methods for writing to the text box:

template <typename T>
void
Write_To_Textbox(const T& variable,
                 const std::string& variable_name,
                 TRichTextEdit & textbox)
{
  //...
}

Then use some cut, copy, paste, and regular expression capable replacement editor functions and create an "annotate" function:

void
annotate(TRichTextEdit& textbox)
{
  Write_To_Textbox(member1, "member1", textbox);
//...
}

Note: Check syntax of template functions, as I don't think I got it right in this example.

answered 2009-12-10T21:36:32.873

Your Answer