C++ Builder IDE >> monitoring a variable

by grahamo » Wed, 07 Dec 2005 00:07:25 GMT


Hi,

I would like to know if it's possible to mark an object under the debugger such that anytime it's accessed the debugger stops (like a breakpoint). Is that possible?

The reason I ask is that I have an object foo which new's an objct in its ctor. The object is publically accessible. e.g.

class foo
{
public:

foo()
{
m_str = new char[100];
}

char* get_str()
{
return m_str;
}

protected:

char *m_str;

// dtors etc. that clean up m_str using delete..
}


the above code is pseudo code. It's possible for a client to do something like this;

foo f;
char* s = f.get_str();
s = 0;

I would like to be able to see whenever somebody accesses the str attribute of the foo class.

Is that possible ? the ide is in francais here so it's not as intuitive to use cpp builder as it normally would.


cheers much

G




C++ Builder IDE >> monitoring a variable

by Bruce Salzman » Wed, 07 Dec 2005 04:17:29 GMT






You can add a Data Breakpoint Run|Add Breakpoint...|Data Breakpoint...
You have to stop the debugger in the scope of the object to do this
(the variable needs to be accessible).
One caveat: I have had poor results getting the debugger to stop when
I want it to.


This shouldn't cause any problems.
*s = 0;
is another story. Is there a reason that get_str() doesn't return a
const pointer?

--
Bruce





C++ Builder IDE >> monitoring a variable

by grahamo » Wed, 07 Dec 2005 15:54:48 GMT


Hi Bruce,

thanks for that. I'll put breakpoints in place.


RE code, it was pseudo code I made up...just to exercise a point.

thanks man and have a nice day.

Graham







Similar Threads

1. Conceptual Problem with Monitor.Enter and Monitor.Exit - CSharp/C#

2. why use Monitor.Enter...Monitor.Exit insted of lock(object9

Hi!

If I want to lock a section in the code from concurrency item problems I can 
use the static Monitor class in this way
Monitor:Enter
...
Monitor.Exit

I can also use the C# lock keyword to lock the same section.

So I don't see any point at all to use the Monitor.Enter... Monitor.Exit 
instead of the lock keword just to lock a section in the code because of two 
reasons.
1. It much less to write lock then the other
2. The most importand it that you get the try..finally for free which mean 
that you will always
free the lock in case of running into same kind of exception

Is this correct understood ?

//Tony 


3. Need to display 4 VCL Forms in 4 diferent monitors (one form per monitor) - Delphi third-party tools

4. Monitor Size Vs Monitor resolution Vs FORMS

Hello all,

I developed a simple application in a 17 inch monitor with a resolution
of 1280x768; When i run the same application in a 14 inch monitor with
a resolution of 1024x768, my form in the right side is truncated.

I have set the following properties;
Anchors-left, top
Autoscroll-true
Autosize size-true
Align-alNone

Can you please advise me, how i can solve this problem.

Many Thanks
Raj

5. 2 monitors - IDE won't maximise in large monitor - C++ Builder IDE

6. Put variables into member variables or function variables?

I modify my code into following sample code.
CTest is a class only constructed once when the device power on.
CTest::ExecuteRunState is a function entered  periodically.
Do you think whether it is necessary to put the local variables into
class private members?
Otherwise, each time entering the ExecuteRunState(), those local
variables will be decleared and initionalized one time. It's a waste
of cpu resource.


 class CTest
  {
  public:
    CTest();
    ~CTest();

  private:
     void CTest(const CTest & m_CTest);
     void ExecuteRunState(); //This function will entered periodically
  };


void CTest::ExecuteRunState()
{

	tMV  measurement = 0;
	tMVq quality = 0;
	tMVt timeStamp = 0;

	//Here those three variables will gain the newest values.
	pData->GetNewestValue(&measurement, &quality, &timeStamp);
	CalFreq(&measurement);
}

7. static variables (class variables) - Delphi/Pascal

8. ?? [Warning]...: For loop control variable must be simple local variable

I do not understand why this message:

[Warning] ... : For loop control variable must be simple local variable

is reported in this case (D6):

unit blabla
...
var k : integer;
initialization
  for k:=0 to 5 do keyTrend[k]:=ThtmlSingleTrend.create;

finalization
  for k:=5 downto 0 do keyTrend[k].free;
end.

The compiler accepts the for-loop in the initialization section. The message 
results from the finalization section.
Tom