Solved

Break on variable change

Posted on 2001-07-31
10
1,061 Views
Last Modified: 2012-05-04
I am using Delphi 1, and I want to know if I can set a breakpoint using debug, but only break when a variable changes?

i.e.

I set a watch on VarName and I want the program to beak everytime the value of VarName changes.
0
Comment
Question by:Brenda-Leigh
10 Comments
 
LVL 4

Expert Comment

by:YodaMage
ID: 6338598
I cheat when doing this. Use a test function like this and it'l do what you want:

procedure TestVarandBreak(VarName : Integer);
var
  value2 : Integer;
begin
  if (VarName <> value2) then
  begin
    Showmessage(inttostr(Val2) + ' changed to ' +
     inttostr(VarName));
    Val2 := VarName;
  end;
end;

Then call this in your loop or when you assign Varname.

 
 
0
 

Expert Comment

by:Yevgen
ID: 6338774
Who's using Delphi 1??? Isnt it a little bit old???
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6339455
Yevgen in some places Windows 3.1 is still used !!!!!. Funny, strange but real.
ziolko.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:Brenda-Leigh
ID: 6340008
Geez, didn't anybody ever hear of maintenance of legacy software?
Aside from that
The application is extremely large, and in the DLL that I want to capture my variable there nearly 100 procedures, so calling the showmessage isn't really practical. But thanks for the idea.
0
 
LVL 3

Expert Comment

by:raidos
ID: 6340501
If you set up a dummy Class that looks something like this.

  TDummyClass = Class
    fVariable : Integer;
  private
    Procedure SetVariable(Value: Integer);
    Function GetVariable: Integer;
  public
    Property YourVarName: Integer Read GetVariable write SetVariable;
  End;

Procedure TDummyClass.SetVariable(Value: Integer);
Begin
  If Value <> fVariable Then
    fVariable := Value; //BreakPoint here
End;

Function TDummyClass.GetVariable: Integer;
Begin
  Result := fVariable;
End;

  Then you will need a global variable for you class. which will need to be created when you initialize the dll, and freed when you close the dll.
  DummyVar : TDummyClass;

  At init, do
  DummyVar := TDummyClass.Create;
 
  At deinit do
  DummyVar.Free;

Then replace every call to set your variable with
  DummyVar.YourVarName := YourNewValue;
 
Atleast thats how i would do it

//raidos
{Code actually tested in D1}
so it should work..=))
0
 

Author Comment

by:Brenda-Leigh
ID: 6341568
Obviously you went to quite a bit of trouble, so thank you very much. I am not sure though that I see the difference in what you suggest and just putting a break point everywhere I call the variable. Which is what I eventually succumbed to(43 breakpoints!). I was hoping that there was some inherent utility in Delphi's Debug that would allow you to do that, after all VB, C++, and even RPG will let you specifiy a condition to break on. Then rather than watching the variable go through all its hoops and loops where the value is not changed, I could just see the call stack when the value actually changes.
0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6341947
breakpoint conditions are available in Delphi 5... But I know that is useless to you at this point.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 8730060
Is this Q still open?
ziolko.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8735036
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To be PAQ/Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0
 

Accepted Solution

by:
RotaredoM earned 0 total points
ID: 8822631
Finalized as recommended.

Question PAQed and 50 points refunded.

RotaredoM
CS Mod @ EE
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question