Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a debug page

Status
Not open for further replies.

Bachatero

Programmer
Aug 30, 2006
36
NL
What is the simplest way to display text with data in a Borland C++ VCL environment. I would like to make a debug page where I can display the contens of an array during runtime. Can I use the printf command in a seperate window under Borland C++. Now, I use the ShowMessage command to display some tempory data.

Sugestions are very welcome.

Thanks in advance,

Johan
 
Are you trying to do this at the command line or in a Window?


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
If posible in a window. I never use the commandline. Is this possible as well?

Johan
 
If the program is run in a command line, yes, you can show a debug info on the command line. However, you can pipe out your error data via cerr but it's unlikely to be seen.

I personally prefer one of the message boxes. For example,
Code:
AnsiString ADOSetupStr = RegGet();
if (ADOSetupStr == "")
{
    AnsiString MsgStr = "ADO is not set up. User Setup Button!";
    //Application->MessageBox(MsgStr.c_str(), "Warning!", MB_OK);
    MessageDlg(MsgStr.c_str(), mtWarning, TMsgDlgButtons() << mbOK, 0);
}

The above example shows how I used either the MessageBox or MessageDlg. If I need to show integers or floats, I convert them into AnsiStrings.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
I would add floating form with memo control (multiline edit). Or add this control to the most active form (well, temporary - for debug).
And add lines of output to it.
 
Thanks for the replies.

My next question is how to format text in a message box.

E.g.: If I would like to display text with an integer in a loop, 'I = ', I;
I used something like:

int i;
AnsiString MsgStr;

for (i=1; i<11; i++) {
MsgStr = AnsiString(i);
}
Application->MessageBox(MsgStr.c_str(), "Waarschuwing!", MB_OK);

However only the last i=10 is displayed in the message box.

How can I format the text so that it wil be displayed in seperate lines ??

Thanks in advance

Johan
 
The simplest would be to use a TMemo component as tsh73 suggested. The MessageBox isn't going to do what you need. Drop a Memo component onto your form, then add lines to it:

Memo1->Lines->Add(MsgStr);
 
You can get the messagebox to work but there is a flaw in your logic.
Code:
int i;
AnsiString MsgStr;
    
for (i=1; i<11; i++) 
{
    // Each time the loop is run, MsgStr is REPLACED with i
    MsgStr = AnsiString(i);
}
Application->MessageBox(MsgStr.c_str(), "Waarschuwing!", MB_OK); // The result is only the last i

Try this instead:
Code:
MsgStr += AnsiString(i) + "\n";

This will add the the string of i to the MsgStr AND include a new line feed so the display will show each value on a new line.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Oh, I didn't look closely at your code Bachatero, I had assumed you would be displaying a large amount of data, but if you only have 10 array elements to display, 2ffat's solution using the MessageBox will work. If you have a lot of data to display however, using the MessageBox won't work, since there is no scroll capability in the MessageBox.
 
Thanks 2ffat, tsh73 and itsgsd,

I use both methods now. The messagebox for displaying a small amount of data and the Tmemo for a loop with 5000 iterations.

Thanks for the replies and help.

Johan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top